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

Is there a reason OPcache can't be statically compiled? #16887

Closed
dktapps opened this issue Nov 21, 2024 · 2 comments
Closed

Is there a reason OPcache can't be statically compiled? #16887

dktapps opened this issue Nov 21, 2024 · 2 comments

Comments

@dktapps
Copy link
Contributor

dktapps commented Nov 21, 2024

Description

I maintain a threading extension ext-pmmpthread.

One of the biggest maintenance issues is the need to copy classes, functions & constants from thread A to thread B when a new thread is started.

If OPcache is enabled, this becomes vastly easier & faster, since the extension doesn't need to copy classes & op_arrays with ZEND_ACC_IMMUTABLE at all. Constants are still an issue right now because OPcache doesn't persist those as far as I'm aware.

However, we still have to account for the case when OPcache is not used (e.g. on platforms where dynamic loading isn't available since OPcache can't be statically compiled, or disabled due to bugs). This means that:

  • A large amount of code is needed to copy the classes, functions & constants in question. This makes up a significant chunk of the extension's code & is also the source of most of the bugs. Many parts of it are adapted from zend_persist.c which does a pretty similar thing.
  • Maintenance on the extension is needed on basically every PHP version to copy-paste & adapt bits of code from zend_persist.c to fix various new issues that come up. Often these issues are not detectable during initial testing.
  • Some things can't be copied in certain situations, such as object constants. This is because the AST for these constants is deleted when the constant is evaluated if OPcache is not used. It's easy to copy AST but difficult to copy objects (particularly internal objects). This leads to weird limitations like threadable code not being able to use certain language features, or needing hacks like serialize (a la ext-pthreads) which don't always work either.
  • Threads take a big performance hit if they need to copy a lot of classes from thread A to thread B.

For completeness, I'll mention that I have considered implementing copying at the point of loading a script (exactly like OPcache does) to avoid some of these issues. However this would involve basically identical logic to zend_persist.c being copied to the extension, which I don't feel makes a lot of sense.

For PHP's own sake it doesn't make a ton of sense to me to have two different modes of class & function existence either. I feel like it would simplify a bunch of things for everyone if the OPcache way was the default.

@dktapps
Copy link
Contributor Author

dktapps commented Nov 21, 2024

Thinking about it, I suppose the reason this has never been done is because it would essentially involve integrating OPcache as a non-removable part of the PHP core, and I guess there's a reason that's never been done.

That being said, if it wasn't for it not being able to be statically compiled, I'd happily make it a hard dependency for my extension. Is there a specific technical reason why it can't be statically compiled?

@dktapps dktapps changed the title Make ZEND_ACC_IMMUTABLE classes/functions/constants the default irrespective of OPcache usage Is there a reason OPcache can't be statically compiled? Nov 21, 2024
@cmb69
Copy link
Member

cmb69 commented Nov 24, 2024

See #15074.

@cmb69 cmb69 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants