Skip to content

perf: keep the JIT trace ID in the exit register snapshot - #25736

Open
henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/jit/trace-id-register
Open

henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/jit/trace-id-register

Conversation

@henderkes

@henderkes henderkes commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

WIP...
benchmarks from docker library (all jit on):

aarch64 (Ampere A1):

BenchmarkNTS (ms)ZTS before (ms)ZTS branch (ms)ZTS change
Zend/bench.php internal total95.0093.0091.00-2.15%
Zend/bench.php wall time109.18107.30105.52-1.64%
arrays41.5140.9441.08+0.36%
fib35.2033.5232.14-4.24%
hash3870.963871.403873.96+0.03%
includes13.0112.8912.92+0.69%
json284.09285.45285.53-0.01%
regex79.6180.1880.18-0.05%
strings109.73110.51110.76+0.27%

x86_64 (13700k P-core):

BenchmarkNTS before (ms)NTS after (ms)NTS change (%)ZTS before (ms)ZTS after (ms)ZTS change (%)
Zend/bench.php internal total38.1537.63−1.37%39.6638.57−2.76%
Zend/bench.php wall time43.1342.65−1.11%44.8243.75−2.39%
arrays19.3219.38+0.31%19.2619.34+0.40%
fib11.2610.85−3.72%13.2612.55−5.33%
hash2,238.442,237.72−0.03%2,235.732,234.97−0.034%
includes3.653.72+1.81%3.743.76+0.61%
json127.85127.38−0.37%129.12128.78−0.27%
regex30.3830.47+0.28%30.2930.26−0.11%
strings41.8941.66−0.56%41.4341.27−0.38%

@henderkes
henderkes marked this pull request as ready for review November 25, 2026 16:01
@henderkes
henderkes requested a review from dstogov as a code owner November 25, 2026 16:01
@henderkes

Copy link
Copy Markdown
Contributor Author

cc @arnaud-lb for review

this one saves only one write per trace entry. the other optimization I dm'd you about gives +~8% performance in recursive scenarios but regresses non-recursive calls by about the same amount.

@arnaud-lb

Copy link
Copy Markdown
Member

It's unfortunate that we have to reserve an additional register. On x86_64 this leaves only one free callee saved register.

Another approach would be to infer the trace num from the trace address. We can find the trace address on the stack if we call the exit stub instead or only jumping to it. Then we need an index to lookup traces from trace address (maybe a dichotomic search on zend_jit_traces if it's sorted, but I'm sure it is). We need to pop the stack frame too, since we are not returning to the trace. This is more involved but this would eliminate EG(jit_trace_num) entirely.

@henderkes

Copy link
Copy Markdown
Contributor Author

Sorry for the slow answer, am still working on the unshare PR for ZTS behaviour.

I think we still have 3 callee saved registers after this. r14+15 are obviously used, r12 is gone with this, but r13, rbp and rbx should be free?

I've not found any regressions from the added register pressure, but I can test the call approach later. Let me just finish the cwd branch first.

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.

2 participants