PoC using the boehm-gc #23
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a rough PoC of using the Boehm GC1 as only garbage collection mechanism for userland internal structures.
Switching to a tracing GC has the following potential benefits:
What this branch does:
e?free()
a no-opRefcounting
Removing refcounting entirely would bring some performance benefits and considerable code simplifications, but we still need it for two things:
For arrays, one solution would be to switch to a functional/persistent data structure.
For destructors and resources there is no ideal solution apart from making resource closing more explicit in applications. Mechanisms like "with" / context managers would help.
Finalization
Objects need to perform some actions before they are released, like calling destructors, calling custom dtor/free handlers, or releasing weak refs.
We rely on libgc's finalization mechanism to be notified when an object is about to be collected. In particular, we use unordered java finalization, which matches what the cycle collector does already.
Performance
Potential improvements:
realpath_cache_bucket
that end with non-ptr data.-DDONT_ADD_BYTE_AT_END
if we don't point to the end of objects (e.g.arg_info
for functions with a return type but no args).ZEND_MM_OVERHEAD
Incremental GC:
Building
libgc:
php:
Caveats / TODO
Footnotes
https://www.hboehm.info/gc/ / https://github.com/bdwgc/bdwgc ↩
https://www.researchgate.net/publication/2926551_On-the-Fly_Cycle_Collection_Revisited ↩
Only in php-src ↩
https://github.com/bdwgc/bdwgc/blob/master/include/gc/gc_typed.h ↩