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

Bring over perf improvement from hhvm/hsl #423

Closed
wants to merge 1 commit into from

Conversation

lexidor
Copy link

@lexidor lexidor commented Sep 28, 2023

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6344316445

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.001%) to 98.998%

Totals Coverage Status
Change from base Build 5862133600: -0.001%
Covered Lines: 4151
Relevant Lines: 4193

💛 - Coveralls

@azjezz
Copy link
Owner

azjezz commented Sep 29, 2023

this doesn't bring any performance improvement, PHP opcache will align the variable later on. the reason for using a separate variable here is to inform psalm that the exceptions thrown int function won't be thrown in this particular case.

@azjezz azjezz closed this Sep 29, 2023
@lexidor
Copy link
Author

lexidor commented Sep 29, 2023

Sorry azjezz, you've missed the reason for this change. The engineers at Meta weren't concerned about an intermediary variable.

Doing the float cast before the division makes this an fdiv, which doesn't check for clean (without remainder) division first. By having two integer operands, this division is performed twice. Once in the integral domain, to determine if the remainder would be zero. And if the remainder is not zero, the division is performed again in the floating point domain.

Since the only clean divisions in the range (0..2^53) over 2^53 are when the first operand are zero or one, this double division is very unlikely to result in a clean division.

I should not have removed the suppression comment and the intermediate variable. I assumed it was to indicate that a division by zero exception was impossible. My removal of the intermediate variable has cluttered the reason for this change.

If PHP's JIT is able to reason that performing an fdiv here is semantically equivalent, hats off for PHP and it's JIT. I naively assumed that, if Facebook didn't optimize the JIT for this, neither would the PHP Group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants