Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100118 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97066 invoked from network); 30 Jul 2017 03:44:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2017 03:44:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=i@lvht.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=i@lvht.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lvht.net from 54.207.22.56 cause and error) X-PHP-List-Original-Sender: i@lvht.net X-Host-Fingerprint: 54.207.22.56 smtpbgbr2.qq.com Received: from [54.207.22.56] ([54.207.22.56:40094] helo=smtpbgbr2.qq.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/A2-07025-A165D795 for ; Sat, 29 Jul 2017 23:44:27 -0400 X-QQ-mid: bizesmtp8t1501386246tm04nacdh Received: from [192.168.1.5] (unknown [218.81.133.196]) by esmtp4.qq.com (ESMTP) with id ; Sun, 30 Jul 2017 11:44:06 +0800 (CST) X-QQ-SSF: 01300000007000108242B00A0000000 X-QQ-FEAT: AoS+/v7jDMbHeFvmVOPDYCxZyPmM9kOuqXDgyG7Ptc1PIKzB/+TrT5cndlkm/ Fu9nsnU6JGRc5RPq9ncU7Av5MgxowpD+tRKuYWzZfdJ1UxxONRQxlI5vMkQWgHNGiW8kl6R p0QwkneTQbdWOa6PWR84YORROeqzRBP4GRkhAOR8xFzUNjIO0WIVXH4VHqa5DrMwRVPphyg 8K61Kq1DLgO8efs416XqA5kT7eCS5F7zn8Ilrgc/47x36Taku6qpcvnBHoklUPYueLVFHnk 8FLg== X-QQ-GoodBg: 0 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) In-Reply-To: Date: Sun, 30 Jul 2017 11:44:05 +0800 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <85C7AE75-18DE-4543-B4DC-BE1186AFAEC7@lvht.net> References: To: Nicolas Grekas X-Mailer: Apple Mail (2.3273) X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lvht.net:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 Subject: Re: [PHP-DEV] Don't add simple objects to GC's roots From: i@lvht.net (Haitao Lv) Hi, internals, > On 26 Jul 2017, at 22:57, Nicolas Grekas = wrote: >=20 > I'm hitting more and more the GC threshold in projects I work on (the = "10k > roots" one), leading to high CPU usage. Usually, the GC finds nothing = to > clean, so this is just a waste of CPU. More and more php frameworks use object/array as an global container to = store config, and these container variable will be used every where, but = seldom introduce the circular reference. Apart from this, these container = variable will always be a huge tree, so iterate them will lead to high CPU usage. > There is a way to work around: just call gc_disable(). But this means > dealing with side effects of the engine in userland. Moreover, this = also > means leaking memory, since meanwhile roots are not populated. In PHP-7.2, the GC_COLLECTABLE flag has been moved into the gc struct, = and this make it possible to prevent gc trace for certain zval. So I propose to make the gc_disable function accept one zval reference = as parameter. And if gc_disable get that zval, gc_disable just drop the = zval=E2=80=99s GC_COLLECTABLE flag, which will hint the PHP gc not to trace that zval. Here is my patch https://github.com/php/php-src/pull/2665/files, and a = demo, name; } $a =3D new stdclass; $a->name =3D 'foo'; gc_disable($a); hi($a); // these will change the refcount of $a, but never trace gc=