fix(profiling) wall-time crash after PHP runs on a native thread in ext-grpc - #4198
realFlowControl wants to merge 3 commits into
Conversation
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 12 Pipeline jobs failed
|
| Test | New execution time | Base Execution time | Increase | DataDog link |
|---|---|---|---|---|
profiling/tests/phpt/allocation_generator_01.phpt ([profiling] profiling should not crash during a from php.profiling.tests.phpt |
25.59s | 614.031881ms | +24.98s (+4067%) | View in Datadog |
profiling/tests/phpt/allocation_generator_01.phpt ([profiling] profiling should not crash during a from PHP.profiling.tests.phpt |
24.04s | 612.656654ms | +23.43s (+3824%) | View in Datadog |
ℹ️ Info
No other issues found (see more)
🧪 All tests passed
❄️ No new flaky tests detected
🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 67.46% (-0.01%)
Useful? React with 👍 / 👎
This comment will be updated automatically if new data arrives.🔗 Commit SHA: 7339fc0 | Docs | View more details | Give us feedback!
ext-grpc
Benchmarks [ profiler ]Benchmark execution time: 2026-09-17 11:31:07 Comparing candidate commit 7339fc0 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 26 metrics, 8 unstable metrics.
|
0506219 to
8fb0387
Compare
8fb0387 to
0dae555
Compare
efaf119 to
7b5940b
Compare
Why
The
ext-grpcextension may execute PHP code on native threads that are not initialized as PHP threads, meaning they never go through GINIT/GSHUTDOWN.CACHED_STRINGS. At this point, everything is fine.CACHED_STRINGS, which frees the strings, but the runtime cache slots still contain pointers to them.Why did our earlier tests not catch this?
We disable the runtime-cache optimization for CLI, where PHPT's are executed in the CLI SAPI, so we could not see it.
Description
This PR makes the string cache process-global on PHP NTS and keeps it thread-local on ZTS.
It is safe because NTS executes PHP on one thread. It requires
unsafe impl Syncbecause Rust cannot verify that guarantee that there is no concurrent access from another native thread. That would cause undefined behavior. Technically thoughext-grpcmight cause an access to this from another native thread, just not concurrent.I am not going to say I am happy with the "fix", but it seems to work.
Reviewer checklist