Repository navigation
Fix GH-25380: Do not cache stateless closures with heap runtime cache - #25545
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
ZEND_DECLARE_LAMBDA_FUNCTION caches closures in the declaring op_array's runtime cache and pushes a reference onto EG(lambda_cache), which is only released at request shutdown. When the declaring function has ZEND_ACC_HEAP_RT_CACHE (Closure::bind/bindTo with scope changes, Closure::call, or closures inside trait methods reused across classes), its runtime cache is freed with the closure or call, leaving unreachable closures accumulating in EG(lambda_cache) for the rest of the request. Skip stateless closure caching when EX(func) uses ZEND_ACC_HEAP_RT_CACHE.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes GH-25380
ZEND_DECLARE_LAMBDA_FUNCTIONcaches stateless closures inEX(run_time_cache)viaCACHE_POLYMORPHIC_PTRand pushes a reference ontoEG(lambda_cache), which is only released at request shutdown.When the declaring function (
EX(func)) hasZEND_ACC_HEAP_RT_CACHE(viaClosure::bind()/bindTo()with a scope change,Closure::call(), or closures inside trait methods reused across multiple classes), its runtime cache isefree()d when the outer closure orcall()finishes. Subsequent calls allocate a fresh zeroed runtime cache, missCACHED_POLYMORPHIC_PTR, and push another unreachable closure ontoEG(lambda_cache)for the rest of the request.Skip stateless closure caching when
EX(func)->common.fn_flags & ZEND_ACC_HEAP_RT_CACHEis set. Because the check sits on the cache-miss write path (and heap runtime caches are zero-initialized), normal arena-cachedZEND_DECLARE_LAMBDA_FUNCTIONcache hits pay no extra cost.Checked sibling caches as well:
ZEND_CALLABLE_CONVERT(EG(callable_convert_cache)) andZEND_CALLABLE_CONVERT_PARTIAL(EG(partial_function_application_cache)) deduplicate in request HashTables and already stay bounded across repeatedClosure::bind()calls.Verification
Zend/tests/closures/: 139 passed, 1 skipped (zend_test)Zend/tests/closures/gh25380.phpt: passed with bothopcache.enable_cli=0andopcache.enable_cli=1ext/opcache/tests/: 1027 passed, 46 skipped, 2 expected failZend/tests/: 5562 passed, 178 skipped, 1 expected fail (new_oom.phptonly failed locally due to an unquoted space in the local workspace directory path)