Repository navigation
Conversation
There was a problem hiding this comment.
Not only is it a CPU time regression, but it also leaks memory on the arena (it's just not reported as a leak, because arena).
Every time the scope changes (e.g. an inherited function called on different extending objects), a new run time cache is allocated.
If you want to meaningfully do this, you'll have to store the closures run_time_cache in e.g. class_mutable_data of the scope they belong to.
Otherwise, I think Dmitrys suggestion was to do this just once. I.e. store the scope for the first time the runtime cache is allocated (i.e. when ZEND_MAP_PTR_GET() is NULL) and otherwise heap allocate.
This would still cause repeated observer initializations, but make it consistent between opcache and non-opcache.
|
Yeah, I planned to analyze the regression and check for mistakes, because I didn't expected that. My goal was only to have a similar reuse rate with opcache than without, but indeed there may be ways to improve that even more.
I'm not sure what you mean here. Do you have an example where the scope of a closure changes? (without binding it explicitly). All I can think of is traits, but even in that case I allocate on the arena only once. With the current changes, I never allocate on the arena more than once per Closure.
That's what I was targeting, but it's possible I've made mistakes that prevent this. |
I see what I missed - the !ptr and the closure check are on two different lines and missed that they belong to the same condition. |
ArtUkrainskiy
left a comment
There was a problem hiding this comment.
This adds to a void *, which is a GNU extension. I don't think MSVC accepts it.
| * and remember which scope it is for. The scope is stored in | ||
| * an extra slot before the run_time_cache. */ | ||
| size_t extra_slot_size = sizeof(void*); | ||
| ptr = zend_arena_alloc(&CG(arena), func->op_array.cache_size + extra_slot_size) + extra_slot_size; |
There was a problem hiding this comment.
| ptr = zend_arena_alloc(&CG(arena), func->op_array.cache_size + extra_slot_size) + extra_slot_size; | |
| ptr = (void **) zend_arena_alloc(&CG(arena), func->op_array.cache_size + extra_slot_size) + 1; |
|
I measured this on Laravel 13 and Symfony Demo, with the PR ported onto master ( These runs used a Ryzen 9 5950X, with OPcache on and JIT off. The table shows median changes in cycles per request against master: 10 alternating passes for the pages, 8 for the worker. Negative means fewer cycles. The OpenTelemetry configuration is the extension with 20 no-op hooks.
Instructions go down 0.1–1.0% in every row, but cycles mostly go up. With GCC, code placement appears to be a substantial contributor. The PR moves the code after Against the padded build, the PR ranges from −0.8% to +0.6% across two series, and the direction is not consistent between them. So the placement control reproduces a slowdown of comparable size, but I couldn't isolate a stable remaining cycle effect. I also tried moving the allocation into a cold function; that variant was still 0.2–1.1% slower than master. Release and ASan/UBSan runs showed no new test failures relative to master. The PR's observer test fails on master with OPcache and passes with the PR. Apart from the Details and scripts are in the report. |
Possible alternative fix for GH-10782
This implements the approach described in #10782 (comment):
Unfortunately this results in a small regression on the Symfony benchmark (0.20% wall time, 0.03% icount).