[GIT-PULLS] [php-src] PR #23291: Share the method's runtime cache with fake closures of the same scope

[email protected] (staabm)
Newsgroups php.git-pulls
Message-ID <[email protected]>
Pull Request: https://github.com/php/php-src/pull/23291
Author: staabm

Creating a fake closure (Closure::fromCallable(), first-class callable syntax, ReflectionMethod::getClosure()) over a method whose runtime cache was not yet initialized allocated a cold per-closure heap cache on every creation. Initialize the method's own shared cache instead - exactly what the first real call would do - so repeated closure creations reuse one warm cache. Trampolines and heap-cache functions keep the per-closure path.

---

after this PR
```
➜  php-src git:(closure) ✗ hyperfine 'sapi/cli/php -n -d opcache.enable_cli=0 closure_from_callable_runtime_cache_bench.php'
Benchmark 1: sapi/cli/php -n -d opcache.enable_cli=0 closure_from_callable_runtime_cache_bench.php
  Time (mean ± σ):     136.5 ms ±   1.4 ms    [User: 132.8 ms, System: 2.3 ms]
  Range (min … max):   133.4 ms … 138.7 ms    21 runs
```

before this PR
```
➜  php-src git:(closure) ✗ hyperfine 'sapi/cli/php_old -n -d opcache.enable_cli=0 closure_from_callable_runtime_cache_bench.php'
Benchmark 1: sapi/cli/php_old -n -d opcache.enable_cli=0 closure_from_callable_runtime_cache_bench.php
  Time (mean ± σ):     150.6 ms ±   1.3 ms    [User: 147.2 ms, System: 2.3 ms]
  Range (min … max):   148.3 ms … 152.9 ms    19 runs
```


benchmark `closure_from_callable_runtime_cache_bench.php`: https://gist.github.com/staabm/20c082674ed880c8fc097b4775f2d7a7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.