Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for PHP 8.2 crashes #41

Merged
merged 2 commits into from
Sep 20, 2023
Merged

Fixes for PHP 8.2 crashes #41

merged 2 commits into from
Sep 20, 2023

Conversation

27pchrisl
Copy link
Contributor

@27pchrisl 27pchrisl commented Sep 20, 2023

This PR changes how arrays are accessed in all the operations. It appears that for some reason the hashtables are becoming non-packed, but I am not sure why. Changing directly accessing arData to using zend_hash_index_find fixes this issue. Under the hood zend_hash_index_find evaluates whether the array is properly packed, and delegates to directly accessing arData. So I think this change should be as performant as it was before, if your arrays are properly packed.

All the tests run successfully with these changes.

There are still deprecation warnings about self and static calls, but it looks like Zephir has not yet developed a fix for this. zephir-lang/zephir#2405

There are also warnings like "Implicit conversion from float 3.3 to int loses precision", which appear to be coming from calls into Zend mod_function. I was not sure of the mathematically correct way to resolve this one.
Minor changes like int to float warnings are also fixed, and a return type of Vector is fixed to match the non-extension code.

(Potentially) fixes #33 and #38

@github-actions
Copy link

github-actions bot commented Sep 20, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@27pchrisl
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@andrewdalpino
Copy link
Member

Awesome @27pchrisl thanks for looking into this for us! Your help is greatly appreciated.

Did you run the benchmarks with these changes yet by any chance? I'm curious to know if we take a performance hit. If there is a performance hit, do you think we could try to find the point at which these arrays become "unpacked" and "re-pack" them as a way to mitigate the performance loss?

@andrewdalpino
Copy link
Member

andrewdalpino commented Sep 20, 2023

There doesn't appear to be much (if any) of a performance impact.

Baseline ...

|---|---|---|---|---|---|---|---|
| MatrixMatrixMultiplyBench | multiply | | 1 | 5 | 112.114mb | 0.015s | ±9.78% |
| MatrixVectorMultiplyBench | multiply | | 1 | 5 | 75.193mb | 0.011s | ±9.72% |
| MatrixScalarMultiplyBench | multiply | | 1 | 5 | 75.119mb | 0.011s | ±1.85% |
| VectorVectorMultiplyBench | multiply | | 1 | 5 | 3.737mb | 0.385ms | ±2.14% |

After your changes ...

|---|---|---|---|---|---|---|---|
| MatrixMatrixMultiplyBench | multiply | | 1 | 5 | 112.114mb | 0.015s | ±12.67% |
| MatrixVectorMultiplyBench | multiply | | 1 | 5 | 75.193mb | 0.012s | ±9.72% |
| MatrixScalarMultiplyBench | multiply | | 1 | 5 | 75.119mb | 0.011s | ±0.19% |
| VectorVectorMultiplyBench | multiply | | 1 | 5 | 3.737mb | 0.393ms | ±58.90% |

Copy link
Member

@andrewdalpino andrewdalpino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! The small "rounding" errors can be handled by allowing a small delta in the unit test.

Ex.

$this->assertEqualsWithDelta($expected, $actual, 1e-8);

@andrewdalpino andrewdalpino merged commit e06ebc8 into RubixML:master Sep 20, 2023
9 of 21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP 8.2 compatibility
2 participants