Turn gc_collect_cycles into function pointer
- Version: 1.2
- Date: 2015-01-07
- Author: Benjamin Eberlei (firstname.lastname@example.org), Adam Harvey (email@example.com)
- Status: Implemented (in PHP 7.0)
This RFC proposes to change
gc_collect_cycles into a hookable function pointer.
The goal is to allow extensions to hook into garbage collection for profiling.
PHP Profilers usually hook into zend_execute and zend_execute_internal to
measure execution time before and after the call. Because Garbage Collection is
FREE_ZVAL (5.*) and during variable/object
release this can happen “undeterministically” in a random function call from the perspective of the developer. This skews reporting actual execution times.
Turning garbage collection into a function pointer would allow to measure the time
spent in garbage collection and substract that from the actual function calls.
This would allow Profilers to correct time spent in execution for accidentally
triggered GC. It would also allow to give hints about inefficient garbage collection
runs that should prompt a developer to consider calling
gc_disable() in userland.
A default implementation
zend_gc_collect_cycles will implement the current behavior.
Adam tested the performance of this change and there was no measurable overhead:
Relation to possible 7.0 extension API refactoring
On the mailinglist a discussion began weather this change should be part of a grand refactoring of hooks and extension API.
Making this change part of a grand refactoring will never lead to the inclusion since as of now, we know of nobody planning on working on the extension API for 7.0.
The RFC proposes to include the change AS-IS and then be part of a refactoring in the future, should one happen.
Backward Incompatible Changes
No changes to userland.
This changes the signature of
Zend/zend_gc.h file and should therefore target only 7.0
Proposed PHP Version(s)
- PHP 7.0
To Existing Extensions
Unaffected PHP Functionality
This does not actually add profiling to garbage collection, it only allows extensions to build this on top.
Patches and Tests
Adam Harvey has a patch for this feature here: https://github.com/LawnGnome/php-src/compare/gc-fn-pointer
Initial discussion on hooking into Garbage Collection: https://github.com/php/php-src/pull/930
Voting started: 2015-01-07 19:31 UTC Voting ended: 2015-01-21 19:31 UTC (14 days)