Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98518 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69742 invoked from network); 14 Mar 2017 15:39:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2017 15:39:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.174 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.128.174 mail-wr0-f174.google.com Received: from [209.85.128.174] ([209.85.128.174:33535] helo=mail-wr0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/85-38004-E9E08C85 for ; Tue, 14 Mar 2017 10:39:10 -0500 Received: by mail-wr0-f174.google.com with SMTP id u48so126801736wrc.0 for ; Tue, 14 Mar 2017 08:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=dtLyUTIH2GKAV1OKWlqC91VEmCDFCN7JewdOM80uSG8=; b=eJ0h8ABNwQp6aoaKod7OvQ4WJ5i+OSHJ3abID36C6Mr/hKhzbAOhMtZugMDyLu4AZ/ 1zssGfXVaMBqor78G5Z0X00ohzxI3JxuWt5SnSfGOqMI6/VpxwVPuBHgjlRa1MviAkeu 84XgeBBjt63gFM6KSbPCz9F6Gu714PZ9YMrC/7xknXyiMyHD/7CbcGnk3PAtVO6Bo30E /UnLTX/S347jhC5b4EAdkhp6SskASwiKwLCyY4ywYd1WPzXLrf6+xedFYwsUhA01dSyb QBNALy1YWk9SngytvPBmO3qdqz3sLaWaXLDTenyhnSsv35nG03GsnCeFl02Vhq2KlamJ o6yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=dtLyUTIH2GKAV1OKWlqC91VEmCDFCN7JewdOM80uSG8=; b=sU0Szz5/05DAyvGqt9WO+C+j4zekLApW03zjYUxtp8avK7aPnkpuFo/Pztpa0HsGt9 YGssfVi1TbbLIOK1RI2n4kFyxtZmQ32o4V1WEzDIiPb9CWIIHp1KlF+srMi7I4nIG0O5 a+qx1osPGvR9t9C47QdAeaEw2+T67VckZJ+WpxOOiYc8nCTudYWEssW0iz3c/wz6ktr7 +BLapnqr5fx9oKgjRM1AFcIlRKfXpAh/MgoOUNtX8mxtSSau745kQyvK96biI/TIMz2/ kZ+pVLya5tzoaUXKRa1fs43xjdK08wnIvlJ08wc7qt5kgBY3kDyB60AxFFlCIGflhaMd s1aw== X-Gm-Message-State: AMke39mHTzR6ENuwa2GZHYZrLavnk4fFQzaK9ot3Fay9DAHWbEFmQmVh1p+7y7oWbv5iOdk0jjoPqxJHMynxMA== X-Received: by 10.223.176.143 with SMTP id i15mr35207076wra.136.1489505946205; Tue, 14 Mar 2017 08:39:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.170.216 with HTTP; Tue, 14 Mar 2017 08:39:05 -0700 (PDT) In-Reply-To: <5BF394D3-919E-4140-AFF9-F46223AB49C4@heroku.com> References: <5BF394D3-919E-4140-AFF9-F46223AB49C4@heroku.com> Date: Tue, 14 Mar 2017 16:39:05 +0100 Message-ID: To: David Zuelke Cc: PHP internals list Content-Type: multipart/alternative; boundary=001a1141b6a0d0ca40054ab2a0f4 Subject: Re: [PHP-DEV] OPcache compilation performance regression in PHP 5.6/7 with huge classes From: nikita.ppv@gmail.com (Nikita Popov) --001a1141b6a0d0ca40054ab2a0f4 Content-Type: text/plain; charset=UTF-8 On Tue, Mar 14, 2017 at 11:29 AM, David Zuelke wrote: > Hi all, > > There appears to be a performance regression in the CFG and DFA based > optimization passes of OPcache in PHP 5.6+ when loading huge classes (such > as those generated by Symfony's routing component) for the first time. > > The issue does not occur on PHP 5.5. Tests below are with 5.6.30, 7.0.16 > and 7.1.2 and default INI settings; I replicated the issue on both macOS > and Linux. > > Test file here (it's from an actual application, slightly anonymized, not > a synthetic example): https://gist.github.com/dzuelk > e/fe867f55f09e0bf79ecefcc815b7fe92 > > Without OPcache, everything is fine in all versions: > > $ time -p php -dopcache.enable_cli=0 hugeclass.php > real 0.10 > user 0.09 > sys 0.00 > > With OPcache on, things are suddenly much, much slower: > > 5.6: > > $ time -p php -dopcache.enable_cli=1 hugeclass.php > real 3.23 > user 3.21 > sys 0.02 > > 7.0: > > $ time -p php -dopcache.enable_cli=1 hugeclass.php > real 1.76 > user 1.73 > sys 0.02 > > 7.1: > > $ time -p php -dopcache.enable_cli=1 hugeclass.php > real 4.01 > user 3.98 > sys 0.02 > > For comparison, 5.5 is as speedy as you'd expect it to be: > > $ time -p php -dopcache.enable_cli=1 hugeclass.php > real 0.14 > user 0.11 > sys 0.02 > > If we switch off optimization passes 5 (CFG based) and 6 (DFA based, only > in 7.1), everything is great again in all versions: > > $ time -p php -dopcache.enable_cli=1 -dopcache.optimization_level=0x7FFFFFCF > hugeclass.php > real 0.13 > user 0.10 > sys 0.02 > > For 5.6 and 7.0, pass 6 is not a thing, but in 7.1, we can inspect passes > 5 and 6 separately. > > Pass 5 (CFG based) already makes for a drastic performance hit in 7.1: > > $ time -p php -dopcache.enable_cli=1 -dopcache.optimization_level=0x7FFFFFDF > hugeclass.php > real 0.88 > user 0.86 > sys 0.01 > > But pass 6 (DFA based) is the one that causes the biggest slowdown in 7.1: > > $ time -p php -dopcache.enable_cli=1 -dopcache.optimization_level=0x7FFFFFEF > hugeclass.php > real 3.29 > user 3.24 > sys 0.04 > > In all versions, subsequent loads from the cache (such as when running FPM > or the built-in web server) are fast. > > Is this slowness with a cold cache expected/accepted, or does that qualify > as a bug? > Yes, this is a bug. Optimization should never be this slow. From a quick perf run, the problem in the DFA pass is that TI is quadratic in the number of calls (as call lookup is implemented as a linear scan). This can be fixed with a more efficient map lookup. The problem in the CFG pass is that a large buffer is zeroed repeatedly. Nikita --001a1141b6a0d0ca40054ab2a0f4--