Hi, I'm hitting more and more the GC threshold in projects I work on (the "10k roots" one), leading to high CPU usage. Usually, the GC finds nothing to clean, so this is just a waste of CPU.
By being super light and fast, objects are nice for many tasks, and the trend is to use them all over the place, e.g. as nodes when parsing a PHP AST. There is a way to work around: just call gc_disable(). But this means dealing with side effects of the engine in userland. Moreover, this also means leaking memory, since meanwhile roots are not populated. I was wondering: does it exist some light algorithm that could prevent hitting the threshold that often? E.g. in my previous example, AST nodes are created free of any circular refs. Would it be possible to add them (and any objects really) to GC's roots list *only* when userland does something that *might* create a circular ref? (e.g. setting a property to a non scalar? or something more clever?) Just raising the topic, as unfortunately I wouldn't be able to do more. Thanks for considering, Nicolas