Skip to content

Remove UNEXPECTED from typed property checks #13143

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

Closed
wants to merge 2 commits into from

Conversation

mvorisek
Copy link
Contributor

as pointed out in #13100 (comment)

currently, I would say typed properties are even more used than non-typed :)

@mvorisek mvorisek marked this pull request as ready for review January 13, 2024 23:06
@mvorisek mvorisek requested a review from dstogov as a code owner January 13, 2024 23:06
@mvorisek
Copy link
Contributor Author

Please review carefully, I did my best, but there might be more places to remove. Also, I wonder if any improvement can benchmarked.

If this really help, maybe all ZEND_TYPE_IS_COMPLEX(...) calls sould be wrapped in UNEXPECTED()? (as complex types are definitely less common than no/simple/simple nullable types)

@Girgias
Copy link
Member

Girgias commented Jan 14, 2024

A zend_type is complex nearly all the time. As a type that contains a class name will also be considered complex, the only types which are simple are ones that just contain built-in types (and those can be unions) so no. Having a type be complex is extremely common.

@dstogov
Copy link
Member

dstogov commented Jan 15, 2024

I would be great to see how this affects performance of different applications.

@dstogov
Copy link
Member

dstogov commented Jan 15, 2024

I don't see any visible performance difference on bench.php, wordpress, symfony hello and symfony demo.

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 15, 2024

If my understanding of the change is correct, the UNEXPECTED (and expanded compiler flag) is used to rearrange if/else, ie. if else is "expected", the if/else is swapped to put the else code first to avoid jump on a call when the CPU branch predictor is cold.

So no huge change is expected, I wonder if there will be any significant performance difference if all EXPECTED/UNEXPECTED will be dropped or even swapped.

@dstogov
Copy link
Member

dstogov commented Jan 15, 2024

Not only swapped, but also sometime move unexpected code into .cold section.
This affects size and locality of the .hot VM code and may cause unrelated stalls.

I don't object against this.

@mvorisek mvorisek changed the title Remove UNEXPECTED from typed prop checks Remove UNEXPECTED from typed property checks Jan 18, 2024
@iluuu1994
Copy link
Member

iluuu1994 commented Jan 18, 2024

Not only swapped, but also sometime move unexpected code into .cold section.

I checked that when we last spoke about this, and it doesn't seem like any of the UNEXPECT(prop_info) cases lead to eviction to .cold.txt, so removing these didn't make a difference to the generated assembly, at least for GCC 13. I still think removing these is the right thing at this point.

@mvorisek
Copy link
Contributor Author

If there are no more questions let's merge this PR, I have no write permission to do it by myself.

@dstogov
Copy link
Member

dstogov commented Feb 12, 2024

I don't object.

@iluuu1994 iluuu1994 closed this in 87edeed Feb 12, 2024
@mvorisek mvorisek deleted the no_unexpected_typed_prop branch February 12, 2024 10:37
@iluuu1994
Copy link
Member

Thanks @mvorisek!

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

Successfully merging this pull request may close these issues.

4 participants