Stateless closure cache: unbounded memory growth when the declaring closure has a heap runtime cache (bind/call/traits)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
The report points to ZEND_DECLARE_LAMBDA_FUNCTION, EG(lambda_cache), and the heap runtime cache used for rebound closures; it does not name source files or tests. Start by tracing the stateless closure cache and compare its behavior for ordinary closures and closures rebound with Closure::bind(), Closure::bindTo(), or Closure::call(). Reproduce with the provided loop and memory measurement, then check that repeated calls no longer grow memory while the closure remains usable.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
ZEND_DECLARE_LAMBDA_FUNCTION caches a stateless (static fn) closure in the declaring function's runtime cache and pushes it onto EG(lambda_cache), which is only released at shutdown. When the declaring function is a closure that gets a fresh ZEND_ACC_HEAP_RT_CACHE on every creation/call (rebinding to another scope via Closure::bind()/bindTo(), Closure::call(), or a closure in a trait method used by more than one class), every call misses the cache and pushes another closure, so memory grows linearly for the whole request. This hurts long-running workers (e.g. Macroable-style Closure::bind($macro, null, static::class)).
The following code:
<?php
class A {}
$outer = function () { return (static fn() => 1)(); };
$m = memory_get_usage();
for ($i = 0; $i < 100000; $i++) {
Closure::bind($outer, null, A::class)();
}
echo memory_get_usage() - $m, "\n";
Resulted in this output:
40243200
But I expected this output instead (as in PHP 8.5.12):
0
Trait variant, no explicit binding:
<?php
trait T {
public function m($k) {
$f = function () use ($k) { return (static fn($x) => $x + 1)($k); };
return $f();
}
}
class U1 { use T; }
class U2 { use T; }
(new U1)->m(0);
$u2 = new U2;
$m = memory_get_usage();
for ($i = 0; $i < 100000; $i++) { $u2->m($i); }
echo memory_get_usage() - $m, "\n";
8.6: 41843072, 8.5.12: 0.
$outer->bindTo(null, A::class)() and $outer->call($obj) grow the same way. The debug build reports no leak because EG(lambda_cache) is cleaned at shutdown. Introduced by f47cd216e95 (stateless closure cache). Reproduces with opcache off, on, and with tracing JIT.
PHP Version
PHP 8.6.1-dev (cli) (NTS DEBUG), PHP-8.6 @ dfc3219f341
Operating System
macOS (arm64)
- Ngôn ngữ chính
- C
- Star
- 41.8k
- Fork
- 8.5k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 145
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
php/php-src#25397 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SNMP accepts malformed remote portsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
php/php-src#25137 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
quoted_printable_encode() produces lines longer than 76 characters for bytes 0xF5 to 0xFFCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
not for AI lovers
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OSGeo/gdal#15515 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Template: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
betaflight/betaflight#16014 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
ly05010419/MacNativeGames#2119 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100