You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ninth step on top of #2287's split. Adds a C-side per-request cache
keyed on the background worker's vars version so repeated get_vars
reads within one request run at O(1) and return the same HashTable
pointer.
## What
- __thread HashTable *bg_vars_cache maps worker name -> { version,
cached_zval }. Initialized lazily on first get_vars call per
request. Destroyed before php_request_shutdown tears down request
memory, so the cached zvals are torn down while their backing
request-memory structures are still alive.
- go_frankenphp_get_vars grew callerVersion / outVersion out-params:
- If callerVersion matches the live varsVersion, Go skips the deep
copy entirely and only reports outVersion. The C side reuses its
cached zval (with ZVAL_COPY for refcount bump).
- If versions differ, Go runs the normal copy-under-RLock path and
reports the fresh version for the caller to cache.
- PHP_FUNCTION(frankenphp_get_vars) consults the cache before calling
Go, then either reuses the cached zval (hit) or stores the fresh
copy (miss). Identity is preserved: $vars === $prev_vars holds
across reads within one request.
## Tests
- TestGetVarsCacheIdentity: two reads in one request return the same
zval (=== true).
- TestGetVarsCacheManyReads: 500 reads in one script complete without
memory corruption, proving the cache tear-down at request end is
correct.
All 16 existing bg worker tests still pass.
0 commit comments