ext-pmmpthread icon indicating copy to clipboard operation
ext-pmmpthread copied to clipboard

Create persistent copies of classes when they are loaded, instead of when they are used

Open dktapps opened this issue 4 years ago • 3 comments

Currently, pthreads makes copies of classes when a new thread is started. This is a problem for numerous reasons:

  • ~~Static properties may have been modified, and since the default values of static properties are not retained (unless opcache is used), we cannot make clean copies of classes. This forces us to copy objects like Threaded objects and other things which might not be copyable, like resources.~~ Resolved since PHP 8.1
  • ~~In PHP 8.1, we will need to copy enum classes, which have object constants. This is problematic for the same reason - we can't conveniently copy objects (although we could copy the AST that instantiates them, but again, without opcache, this is typically not retained).~~ Resolved by other means
  • Static variables of functions may have been modified (same problem as with static properties).

We can avoid all of these issues by copying the class to persistent memory when it is loaded, exactly the same way that OPcache does.

dktapps avatar Aug 03 '21 12:08 dktapps

Could this be related to https://github.com/pmmp/pthreads/issues/63 ?

polyphia avatar Sep 13 '21 15:09 polyphia

This isn't a bug report, so it's not related that way, no. I have no idea what's behind #63 since I haven't investigated it yet.

dktapps avatar Sep 13 '21 18:09 dktapps

Alright thanks for updating, just considering the possibitily of having to copy classes causing an extra delay in Pool::Submit , which seems to be aligned with the https://github.com/pmmp/pthreads/issues/63 issue disappearing when opcache cli is enabled .

polyphia avatar Sep 13 '21 19:09 polyphia