Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102060 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60773 invoked from network); 19 Apr 2018 15:17:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2018 15:17:11 -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.223.171 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.171 mail-io0-f171.google.com Received: from [209.85.223.171] ([209.85.223.171:37504] helo=mail-io0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/2E-38944-0F2B8DA5 for ; Thu, 19 Apr 2018 11:17:07 -0400 Received: by mail-io0-f171.google.com with SMTP id y128-v6so7017843iod.4 for ; Thu, 19 Apr 2018 08:17:04 -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=XxCI6t6QgNt/WUAPS4HnRMQ6SNnESNuUoqXc0bSHaA4=; b=Y1Wu6jpSrkb/C8m1dkKB6lAXqvStQFECgUUSDiDjnnpZ37Zr3XF/OwJaE2bFf25wN6 bXfml5c++2lE+MtMtW3cdQdB0TVJBfZAixFcmKUjB7PC5f01V6k6c9FLnFQ0VxCek7Uk tKgNFEitufpguzgrwgq6BFuZpH0bqnwtSmdN9cTo0oPtIrYRX7xGpkd6jLcVkNYrNLVd tOeRrr6RZjB0/o5TAEOYtum9tIKNj15gfybhxwy8k+muJlw5ebQtwVKEZWcr5JZx/CNi mjbgpms1cvWVMhjsjW11tJ41cdcaO6DnoldhLJGOJ+BsNpZ4uP2xeyZEghPdlQf+hXxj lnCQ== 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=XxCI6t6QgNt/WUAPS4HnRMQ6SNnESNuUoqXc0bSHaA4=; b=lm3l9HALR1+F/x6krHXOV92y5HDCnktw3rEvXVT3LU/VSJafLknBu9a+yLSRVXl1Q/ vryFTwWM/MB1s9bVvgX1nvMh3uxvOePAIaqn4yjrbqcQGPUmhE4xvxFMfaAkfyanTSEe qvPu6pim+qusDpcelgWel40/+idP8/nPTKNX1U2FcfNVr4ll3cvx+9Rh5xtDXy4+Tbca t6h0jFZKNebl/IJPn6OvuIq3/QxWVtXqvCwyAr6VdVk1SqH/72oeouInBBWhvwOILRyk RWPIzHnWPBIgmMubMhEKDLNRe4Pkve3d3HaNT303yzWrE+5ujmv/gjEWCU1peqFo05sa muMw== X-Gm-Message-State: ALQs6tD9Z8+W6erIFEI2MNLnydnkuYRaiT5Sy1L2o93cyVPMjNxDIDEe nFIALeqZpsPsgBsmi7rAG/vYRv1KVKvA97Knuio= X-Google-Smtp-Source: AIpwx48n0c48O/+PlsS3Ro5Op3DtvC8T2pcEFxYPpOdLtCImTjFC/8V1QytnYsA3+ROYtei4f3UnZTDgo8rQYCvVTQg= X-Received: by 2002:a6b:10d1:: with SMTP id 78-v6mr6870374ioq.98.1524151017879; Thu, 19 Apr 2018 08:16:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.154.76 with HTTP; Thu, 19 Apr 2018 08:16:57 -0700 (PDT) In-Reply-To: References: Date: Thu, 19 Apr 2018 17:16:57 +0200 Message-ID: To: Nicolas Grekas Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000160cb056a351018" Subject: Re: [PHP-DEV] Performance optimization ideas for PHP 7.3 From: nikita.ppv@gmail.com (Nikita Popov) --0000000000000160cb056a351018 Content-Type: text/plain; charset="UTF-8" On Thu, Apr 19, 2018 at 4:10 PM, Nicolas Grekas < nicolas.grekas+php@gmail.com> wrote: > Hello internals, > > During the last months, I've been working on optimizing Symfony/Twig for > PHP7. > I found a few situations where the PHP engine could likely be optimized, > and where it would benefit real-world apps. > > In each case, these might look like micro-optimizations, but they are not > in hot loops. > Here are the links to issues I created in the php bug tracker: > > - Class constants are slow: they should be inlined at runtime - > https://bugs.php.net/76178 This should in principle be straightforward. We just need to add a runtime cache for the constant lookup (or more generally, the constexpr AST evaluation). Possible complications: * The responsible opcode ZEND_RECV_INIT already uses a runtime cache slot for the class typehint, so there might be a bit of juggling involved in the runtime cache allocation. It might be easiest to always allocate the class name cache slot if the default value cache slot is used, even if it's not necessary, to avoid making this too complicated. * Some thought needs to be put into whether this is really valid in all cases. Apart from the things we already ignore in other runtime caches (value of a constant might change due to NS fallback), there are other cases to consider, such as `function($foo = "" . M_PI)`. The output could change at runtime based on the LC_NUMERIC locale and the precision ini setting, so the default value might change between calls. However, we already ignore this issue during compile-time evaluation, so I wouldn't consider this to be particularly problematic. > - Add array_key_exists() to the list of specialy compiled functions - > https://bugs.php.net/76148 > This is also straightforward. This will have to be a new opcode, because the key behavior is subtly different (e.g. for floating point keys) than in isset(). (And isset has all kinds of special handling not relevant to this.) > - Don't trigger copy-on-write when assigning same value - > https://bugs.php.net/76150 > This one on the other hand would be a major change, and I'm not sure it's a beneficial one (on average). It might give a large improvement for the specific, rare case discussed in the bug report, but will be a minor regression (on a very common operation) for everything else. > As a bonus, I also created this one today: > - Add hrtime() to zend_try_compile_special_func() - > https://bugs.php.net/76241 > > It would be awesome if those ideas could be implemented in a future PHP > version. > (I'm sorry I don't have the knowledge to do it myself.) > > Keep up the good work! If someone wants to try their hand implementing the 1st or 2nd optimization, feel free to ping me for some pointers. Nikita --0000000000000160cb056a351018--