Skip to content

perf: don't copy zend_constants into every threads EG(zend_constants) table#22729

Open
henderkes wants to merge 2 commits into
php:masterfrom
henderkes:perf/zts_thread_alloc
Open

perf: don't copy zend_constants into every threads EG(zend_constants) table#22729
henderkes wants to merge 2 commits into
php:masterfrom
henderkes:perf/zts_thread_alloc

Conversation

@henderkes

@henderkes henderkes commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

instead keep the immutable variables in a global and perform a two-step lookup (thread local EG(zend_constants) still holds define'd and dl() symbols - if none exist it's still one lookup on only the global table)

this is most useful for frankenphp thread scaling scenarios where a large number of threads can be spun up momentarily, or of course ext-parallel

saves 846k instructions and 135kb (plus the allocations that go with it) per thread spawn on x86_64-linux-gnu. I didn't test aarch64

…onstants) by falling back to a global constant table

before: zend_constants copied all constants into each threads EG(zend_constants)

after: zend_constants stays in a global, per-thread EG(zend_constants) becomes a small per-thread lookup table for define/dl and a runtime read falls back to the global when the per-thread table doesn't contain the key
# Conflicts:
#	ext/reflection/php_reflection.c
@henderkes henderkes force-pushed the perf/zts_thread_alloc branch from 320a999 to cd67e83 Compare July 14, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant