Conversation
|
@dstogov Do you think this makes sense? It seems like our minimum GC threshold of 10000 is also problematic for some workloads, and we probably should allow going below it. |
Zend/zend_gc.c
Outdated
| @@ -1476,6 +1479,7 @@ ZEND_API int zend_gc_collect_cycles(void) | |||
| * short of rerunning full GC tracing. What we do instead is to only run | |||
| * destructors at this point, and leave the actual freeing of the objects | |||
There was a problem hiding this comment.
Comment should also be updated to avoid confusion when reading this later. Something along the lines of "only run destructors at this point, then automatically re-run GC at most once after calling the destructors."
I think, this shouldn't make a big problem. Did you estimate the impact of the patch on something GC hungry? e.g. PHP-Parser, composer,...?
10000 was selected to run most web applications without GC overhead. I'm not sure what kind of loads do you mean and if we should decries GC threshold. Probably, better to trigger GC when memory_limit is exhausted. |
I checked that there is no visible impact on PHP-Parser / Composer. However, it's probably not very meaningful, because both projects don't really use __destruct.
To be clear, I'm not suggesting to lower the default of 10000, just to allow going below it if we find that GC is very "effective". I agree though that triggering GC when we run close to memory_limit may be a better starting point. |
Since PHP 7.4 objects that have a destructor require two GC runs to be collected. Currently the collection is delayed to the next automatic GC run. However, in some cases this may result in a large increase in memory usage, as in one of the cases of https://bugs.php.net/bug.php?id=79519. I have also had some reports (though I don't remember from where) there code depended on gc_collect_cycles() destroying everything in one call.
This patch will automatically rerun GC if destructors were encountered. I think this should not have much cost, because it is very likely that objects on which the destructor has been called really are garbage, so the extra GC run should not be doing wasted work.