Skip to content

Share closure run time cache when possible for improved closure performance - #25683

Open
ndossche wants to merge 1 commit into
php:masterfrom
ndossche:closure-rtc-sharing
Open

ndossche wants to merge 1 commit into
php:masterfrom
ndossche:closure-rtc-sharing

Conversation

@ndossche

Copy link
Copy Markdown
Member

This allows sharing the cache slots on a real (i.e. non-fake) closure's op_array. We can write the scope into the arena region itself so we can easily compare against it.

…rmance

This allows sharing the cache slots on a real (i.e. non-fake) closure's op_array.
We can write the scope into the arena region itself so we can easily
compare against it.
@github-actions

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

Attribute Value
Environment aws
Instance type c6id.metal
Architecture x86_64
CPU Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settings disabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM 251 GB
Kernel 6.18.56-125.164.amzn2023.x86_64
OS Amazon Linux 2023.12.20261026
GCC 14.2.1
Binary layout strategy bolt-align
Time 2026-11-23 22:18:48 UTC
Job details https://github.com/php/php-src/actions/runs/45267786788 (Artifacts)
Changeset https://github.com/php/php-src/compare/2550ff2bac..22a63da9a7

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@2550ff2 (NTS) 0.38075 0.38196 0.00027 0.07% 0.38117 0.00% 0.38108 0.00% 1.121 0.000 1.000 31.29 MB
PHP - closure-rtc-sharing (NTS) 0.37761 0.37879 0.00025 0.07% 0.37805 -0.82% 0.37800 -0.81% 1.048 8.614 0.000 31.28 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@2550ff2 (NTS) 0.68888 0.71535 0.00419 0.61% 0.69036 0.00% 0.68941 0.00% 5.195 0.000 1.000 31.70 MB
PHP - closure-rtc-sharing (NTS) 0.68847 0.72823 0.00573 0.83% 0.69020 -0.02% 0.68900 -0.06% 6.261 4.567 0.000 31.67 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@2550ff2 (NTS) 0.58660 0.59131 0.00080 0.14% 0.58741 0.00% 0.58722 0.00% 3.727 0.000 1.000 31.76 MB
PHP - closure-rtc-sharing (NTS) 0.58710 0.59143 0.00081 0.14% 0.58787 0.08% 0.58760 0.07% 3.224 -5.649 0.000 31.75 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@2550ff2 (NTS) 0.45171 0.45572 0.00055 0.12% 0.45277 0.00% 0.45274 0.00% 3.094 0.000 1.000 31.76 MB
PHP - closure-rtc-sharing (NTS) 0.45228 0.45415 0.00038 0.08% 0.45309 0.07% 0.45302 0.06% 0.515 -4.274 0.000 31.75 MB

@ArtUkrainskiy

Copy link
Copy Markdown
Contributor

This is the idea from GH-10782, as in #18556. Output matches master on a differential test across scopes. Zend, opcache and zend_test tests pass under ASan with and without opcache.

Change in cycles against master with opcache on, negative = fewer cycles (faster):

case master, cycles with GCC GCC 15 clang 21
method creates and calls a closure that uses 15 cache slots 593 −31% −34%
method creates and calls a closure with no cache slots 360 −2% −9%
trait method creates and calls a closure, trait's second class 356 +7.5% +1.2%
closure bound to another class on every call 369 −0.4% +0.5%
empty closure bound to another class on every call 340 −5.4% +6.8%
Laravel / page 8.5 M −0.4% +0.4%
Laravel /users, 100 models as JSON 58.0 M −1.1% +0.7%
Symfony Demo /en/blog/ 30.1 M −0.2% +1.0%
Laravel worker loop, per request 27.3 M −1.2% +1.4%

The trait and empty closure rows run the same instructions as master, within 0.5%. Pages run 0.1–0.5% fewer. So I think the slower rows are code layout, like on #18556.

It also fixes part of GH-25380. A method that creates a closure with a static fn inside no longer leaks under opcache. Bind, call and a trait's second class still need #25545.

Could you add a test? observer_closure_04.phpt from #18556 fails on master with opcache and passes here.

One difference from #18556 is closures with no cache slots. They get a new emalloc(0) whenever the scope differs from the first one, on bind or in a trait's second class. That's about 10% more instructions per call than #18556 there.

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