Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82932 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48297 invoked from network); 17 Feb 2015 07:46:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 07:46:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.192.172 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.192.172 mail-pd0-f172.google.com Received: from [209.85.192.172] ([209.85.192.172:38948] helo=mail-pd0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/00-46567-7E1F2E45 for ; Tue, 17 Feb 2015 02:46:47 -0500 Received: by pdjy10 with SMTP id y10so41970790pdj.6 for ; Mon, 16 Feb 2015 23:46:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ClxfXTxUdzjhHJ+UYThRO5vcfDLKWe1hclDfAjf2qzg=; b=RwXotPEXXrr6cpCiTUtsIv3ESq0Y0WD5BinyDx/Q8Z+Ttyx/CTGwC7/0yhZ3zp48+z GqsDl/4lXCYFc3taemyoLVjNnQa5DSj5ipch+paFqtnwFqiVJ9V80UZx+ijVK41ZnGKz 0WtBXvQQIm5mJVQScEdwHB/x8EOzF5jIHRDs5YZfIiFyljPW/SJtFYpDd2VpcFYNvuqh qYLbHAWngIZsnaTW7RChFby0fOrQ9QPDVQAG4GlwPAsRcezmKZoihg7ds/FUxfKwOKg7 GLZ10K9c2KqIfBDM2hBLx4sUcKFU6usVbBZGIVwo5xt9idK1u6BSPdtql4ndKlNYCJM1 BmbA== X-Gm-Message-State: ALoCoQnamNhukHth2Wl9iBtAfNz8JCRhEWo7A6qAMN4YbhSwiERm+DksJhsx7XimApblC/LcXnoh MIME-Version: 1.0 X-Received: by 10.70.0.176 with SMTP id 16mr3221437pdf.78.1424159204537; Mon, 16 Feb 2015 23:46:44 -0800 (PST) Received: by 10.70.49.100 with HTTP; Mon, 16 Feb 2015 23:46:44 -0800 (PST) X-Originating-IP: [86.190.233.59] In-Reply-To: References: Date: Tue, 17 Feb 2015 07:46:44 +0000 Message-ID: To: Dmitry Stogov Cc: Bob Weinand , PHP Internals Content-Type: multipart/alternative; boundary=047d7b6787107df761050f43e77c Subject: Re: [PHP-DEV] Switch jumptable optimization From: pthreads@pthreads.org (Joe Watkins) --047d7b6787107df761050f43e77c Content-Type: text/plain; charset=UTF-8 Very clever ... thanks bob :) Cheers Joe On Tue, Feb 17, 2015 at 6:46 AM, Dmitry Stogov wrote: > On Tue, Feb 17, 2015 at 2:04 AM, Bob Weinand wrote: > > > I'd like to show you my recent work on a jumptable optimization for > > switches. > > > > https://github.com/php/php-src/pull/1048 < > > https://github.com/php/php-src/pull/1048> > > > > It is a fully transparent optimization of switches, by putting a new > > ZEND_SWITCH opcode at the top of the switch in case we can build a > > jumptable, which is the case if the cases are only scalars (no doubles) > or > > evaluate to them at compile-time. > > > > Switches tend to be big sometimes with a lot of static (literals or > > constants usually) cases, which was a comparison for each case, and now > > just a simple hashtable lookup is needed, which greatly improves > > performance. In case where the result of the switch can be determined at > > compile-time, it even replaces the comparisons with a simple ZEND_JMP > > opcode. > > > > In synthetic benchmarks the results are mind blowing, but in practice, > > benefits mostly are stateful userland parsers (often called with > sometimes > > big switches), where it makes it a few percent faster. (For more concrete > > numbers see > https://github.com/php/php-src/pull/1048#issuecomment-73032647 > > ) > > > > As the optimization is only done if there are 3 or more cases, the lookup > > is always faster than the single comparisons. So there's no negative > > performance impact. > > > > It already works, except with opcache where the CFG optimization pass > > still lacks support. Dmitry or Laruence volunteered to add support for > > opcache. > > > > I'd like to know if there are any technical objections to the PR. If not, > > they will add opcache support and merge it in. > > > > Thanks, > > Bob > > > The patch looks interesting. > We will implement support for opcache and then analyze its impact on > performance. > I see it as a self-containing feature that won't affect anyone (except > opcache and may be debuggers). > I'm not going to work on it in nearest days or weeks, because of more > critical tasks. > > Thanks. Dmitry. > --047d7b6787107df761050f43e77c--