Re: [Proposal] OPcache: share identical opcode arrays between cached scripts (opcache.enable_dedup)

From: Date: Tue, 01 Dec 2026 13:37:44 +0000
Subject: Re: [Proposal] OPcache: share identical opcode arrays between cached scripts (opcache.enable_dedup)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-133274@lists.php.net to get a copy of this message
Hi Arnaud, Thanks for the careful review. Point 2 turned out to be real. I reproduced it on 8.6.0: two traits that declare an identical method no longer collided, a PFA call site that receives two functions with the same opcodes called the first function both times, and ReflectionMethod::invoke() accepted a different closure with the same code. I've fixed it without touching each of those places. OPcache now never shares the opcodes of trait methods, closures, or op_arrays that create a PFA, and dedup is off under phpdbg. The one engine change is in the PFA call-site cache: it now identifies the called function by the function itself (closures excepted), the same way OPcache's PFA cache key already does. There are regression tests for each case, and the differential fuzzer was moved off closures so it still exercises sharing. The fix costs 2.5% of the savings on five WordPress sites in the benchmark. It has now run for a week in production on the same ~80 WordPress sites as before: no crashes, and OPcache memory is still about 41% lower than without dedup. To keep future maintenance cheap, the patch repository has a check that lists every comparison of opcodes pointers in php-src and fails on any that hasn't been reviewed. For php-src itself, the rule would be a comment on zend_op_array.opcodes saying it may be shared between distinct functions and is not an identity. Updated branch: https://github.com/studio-vitalyn/php-src/commit/e170f5cf That doesn't settle your other points. The complexity is real, and so is the exclusivity with the JIT and the file cache. On security, I agree that tenants of unequal trust shouldn't share SHM. The attack in step 3 requires native code execution, which already gives read-write access to every cached script without dedup. Would a PR on this basis be worth your time, or do you see points 1 and 3 as blockers? Best regards, Jean-Christophe > Le 23 nov. 2026 à 14:16, Arnaud Le Blanc <arnaud.lb@gmail.com> a écrit : > > Hi Jean-Christophe, > > On Tue, Nov 10, 2026 at 10:00 AM jc@vitalyn.com > <mailto:jc@vitalyn.com> <jc@vitalyn.com > <mailto:jc@vitalyn.com>> wrote: >> 1. Is a PR with discussion enough, or do you want an RFC for a new >> opt-in INI directive? > > Thank you for the detailed write-up and numbers. > > This is mostly a technical change, so it can be discussed directly in a PR without an RFC. That > said, I have a few concerns: > > * The results are impressive for this use-case, but this adds complexity to an already complex > part of the code base. Unless it benefits more general setups, I'm not sure the maintenance > cost is worth it. > * It breaks the assumption that two functions with the same opcodes are the same function, > which we rely on in a few places (e.g. trait linking, phpdbg breakpoints, PFA caching, > Closure::__invoke). > * It adds more constraints to future work (the feature being mutually exclusive with JIT and > the file cache illustrates that). > * As the security review shows in "Step 3", under the stated pre-existing > capabilities a tenant can break into others. I wouldn't recommend sharing the same SHM segments > between tenants. > > Best Regards, > Arnaud

« previous php.internals (#133274) next »