Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82931 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43183 invoked from network); 17 Feb 2015 06:46:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 06:46:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.171 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:52910] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/73-24654-2C3E2E45 for ; Tue, 17 Feb 2015 01:46:27 -0500 Received: by mail-vc0-f171.google.com with SMTP id kv19so12039938vcb.2 for ; Mon, 16 Feb 2015 22:46:24 -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=eBgH+uWISMpFXuBA+sMtdBWYEnXyhn6oRP04u/E1tMI=; b=ZLot26B83uUy+KWHb0oSSxWHjqyCTGjMnMZR+CbMUVyz0c2eKq+IQ+wdAjSam5Gq8G 0e2N31pzn2A2c9RdccQs3NLQGzLUSIDqh+ZN2oN43y1wcYQ6lFvlkBN/Jql2GzkgZSM4 et3cl8zitC0Oacsux1kdgqDHZAgWPDwk6NUp0RuPXnvK//gG9nd18l2EHJ+YG/BQDLbA F+npC31q5KdZ2uH61onOZ4pCOKpplihFbl5Kg9d7B7tELIFY5CUglH1cL9N6z/AY5Opw FI+Ewb8n1ZQXHq/YiO/gPjQjskT1HpMkBFIUHtmrB4syCkNnV/f67EgawkMxVq89m7pD YRPw== X-Gm-Message-State: ALoCoQkodqCM3dFnOm1MqaDtFAoRsauv8PafpwQGEOK23WYdfZ+kO+oiQV8MJ/RFciGuapKSUqB2XDsh6EPtZf9VUzR4/7p4iKEXHCivssD84h0qbRf+yuJm37LKVFhcUVBpv+bbqS1caA2PmCsHnCz/BknXzQO9FQ== MIME-Version: 1.0 X-Received: by 10.52.162.72 with SMTP id xy8mr15482554vdb.12.1424155584307; Mon, 16 Feb 2015 22:46:24 -0800 (PST) Received: by 10.52.74.73 with HTTP; Mon, 16 Feb 2015 22:46:24 -0800 (PST) In-Reply-To: References: Date: Tue, 17 Feb 2015 10:46:24 +0400 Message-ID: To: Bob Weinand Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e01628326b537b9050f430f90 Subject: Re: [PHP-DEV] Switch jumptable optimization From: dmitry@zend.com (Dmitry Stogov) --089e01628326b537b9050f430f90 Content-Type: text/plain; charset=UTF-8 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. --089e01628326b537b9050f430f90--