-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Infer static for closures #19941
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
base: master
Are you sure you want to change the base?
Infer static for closures #19941
Conversation
@dktapps Ping. I haven't done any benchmarking yet. |
This isn't caching static closures yet, right? So there should be no observable effect on performance |
Right. IIRC static closures themselves have a small benefit, though I didn't see it in the CI benchmark. I'm not sure if maybe Symfony already uses linting to add static. |
Okay, testing Symfony Demo with all static closures turned into non-static ones shows virtually no improvement. Regardless, they should benefit if we can cache them. I'll try this in the same PR then, given this one isn't useful on its own. |
One drawback of non-static closures is that they retain Big +1 on this. |
zend_error(E_WARNING, "Cannot bind an instance to a static closure, this will be an error in PHP 9"); | ||
return 0; | ||
// FIXME: Restrict this workaround to implicitly static closures? | ||
// Will need an additional fn_flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a zend_closure
flag, passed to zend_create_closure()
by ZEND_DECLARE_LAMBDA_FUNCTION
. The flag can be stored in OBJ_EXTRA_FLAGS()
as there is no other place to store a flag in zend_closure
. I do this in the pfa branch: https://github.com/arnaud-lb/php-src/blob/23dce325280c7c6c90043ad3bf830073f6838df3/Zend/zend_types.h#L873 + https://github.com/arnaud-lb/php-src/blob/23dce325280c7c6c90043ad3bf830073f6838df3/Zend/zend_closures.c#L31
6159936
to
637bcd9
Compare
Quick test: In Symfony Demo with all static closures turned into non-static ones, this patch can turn 122/283 into static ones. That's ~43%, so not bad at all. How many of those can also be cached remains to be seen. |
See #19754 (comment)