Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100048 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41321 invoked from network); 26 Jul 2017 14:58:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2017 14:58:14 -0000 Authentication-Results: pb1.pair.com header.from=nicolas.grekas@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nicolas.grekas@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.181 as permitted sender) X-PHP-List-Original-Sender: nicolas.grekas@gmail.com X-Host-Fingerprint: 209.85.223.181 mail-io0-f181.google.com Received: from [209.85.223.181] ([209.85.223.181:37908] helo=mail-io0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/F7-49004-50EA8795 for ; Wed, 26 Jul 2017 10:58:13 -0400 Received: by mail-io0-f181.google.com with SMTP id g13so68537003ioj.5 for ; Wed, 26 Jul 2017 07:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=ats/x9P2N5QS+z1CLbsDnobMZgz/5xJ3b169kVkqOvA=; b=Ik2JrXS2GHDEdRKMMMoMdyWN7fn7wndW5LD8qp/So46lu+pDFDr2dJc7MRBjGVulxn 9NGF8IVSRjNUpt7T4fDCIq8Zk+AjWjiGunaQvjhs1WgunUbcpi1h7C0r2pjluCVOn/wu Zg1j2Ddfwmx3rNHZPEm6bTq0F6c2oAqQtbZ6NcnOJaCX2j/2mdnjLSUIifhgC8tT4D3L +hgc1xq9VS160lIGGxYse2O984Gs8LdgM6F/6kHnxME8aU/Tn54qtBhlbmrZ9ifyYwtU MvbUUQHKmyOHph5omdMsnoelEM6ynpXMaQfweDwcn9SNGEKo+yq1abOVJjX75IbDFeAW RWAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ats/x9P2N5QS+z1CLbsDnobMZgz/5xJ3b169kVkqOvA=; b=HTxh+DbmvHG/AHDjuVLUAeutIuXZij7Fik7Hctnf3PCAjBzIMazOsNOUWApfQoNMJ2 HX+Bk0TtHHd43yue2TFQlm/hLj+Yu1FM6WoyCeNCqrGmbh+CQNZ0HgVCMZRlgX2uRwyM SGPS8pkBp+qvqkgPW8pguiZB9yAPToLDChCZN9U4X45toRXcRH15NAh+8CGBwrlMinjn j7K4W+4ICC0IqczlnxW1RitZSwZSTTn1mP+G15im7xX8ndTYD4if0fvVa+JWg2kjwKCC g24Wkbgmiw2TxKKyPYEjE+Wc70wF6gbPfC1DgVqCciyfqsgmKeEJV5u5GksDyPZgREBT cj0w== X-Gm-Message-State: AIVw112j01NSiFyNpyOgVsFiPuwrvaK1YE0ExR5AY30lrXWdjZc+D2QX RCL+TrSyyeysoQA/nDhbajfavMeeChuS X-Received: by 10.107.133.151 with SMTP id p23mr1453413ioi.328.1501081090401; Wed, 26 Jul 2017 07:58:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.131.208 with HTTP; Wed, 26 Jul 2017 07:57:49 -0700 (PDT) Date: Wed, 26 Jul 2017 16:57:49 +0200 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="001a113ec2ac2c3103055539ada0" Subject: Don't add simple objects to GC's roots From: nicolas.grekas@gmail.com (Nicolas Grekas) --001a113ec2ac2c3103055539ada0 Content-Type: text/plain; charset="UTF-8" Hi, 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. By being super light and fast, objects are nice for many tasks, and the trend is to use them all over the place, e.g. as nodes when parsing a PHP AST. 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. I was wondering: does it exist some light algorithm that could prevent hitting the threshold that often? E.g. in my previous example, AST nodes are created free of any circular refs. Would it be possible to add them (and any objects really) to GC's roots list *only* when userland does something that *might* create a circular ref? (e.g. setting a property to a non scalar? or something more clever?) Just raising the topic, as unfortunately I wouldn't be able to do more. Thanks for considering, Nicolas --001a113ec2ac2c3103055539ada0--