[php-src] PR #19709: PoC simple generational GC

From: Date: Thu, 04 Sep 2025 17:43:08 +0000
Subject: [php-src] PR #19709: PoC simple generational GC
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-33076@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/19709 Author: arnaud-lb This is a PoC of making the GC generational. In some applications, there is an object that transitively references everything (e.g. the DI container or the UnitOfWork), and many objects transitively reference the root as well. As a result, most GC runs in these applications will end up scanning the entire application. Based on that, a generational GC _should_ improve throughput to some degree. Unlike a tracing GC, we don't need to keep track of created inter-generational references, so this turns out relatively simple. 1. Nodes that are scanned but not collected during a run are marked as OLD 2. There are two kinds of GC runs: Partial and full. Partial runs ignore OLD nodes during trial deletion and other steps. 4. gc_possible_root() adds OLD nodes to a separate buffer that doesn't count towards the threshold 5. At the end of a partial run, OLD roots are moved to a separate buffer. This buffer is appended to the roots before full runs. This is enabled by setting the environment variable FULL_GC_FREQ to a non-zero value (e.g. 10 will run a full GC every 10 runs). I've used the following script to test this PoC: https://gist.github.com/arnaud-lb/6bfb493f361e056979571941f1b85990. This simulates a typical Doctrine or Symfony application. The benchmark runs 10-20% faster when the root object (the Tree class) is large, or it creates garbage often (keeping the threshold low). The benchmark runs slower when the root object is relatively small and does not create garbage often, as the non-gen GC will keep the threshold high in this case. This could be mitigated by improving how the threshold is adjusted in the gen GC.

« previous php.git-pulls (#33076) next »