Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85430 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79825 invoked from network); 24 Mar 2015 05:31:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Mar 2015 05:31:59 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.46 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.192.46 mail-qg0-f46.google.com Received: from [209.85.192.46] ([209.85.192.46:34433] helo=mail-qg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/51-04797-DC6F0155 for ; Tue, 24 Mar 2015 00:31:58 -0500 Received: by qgep97 with SMTP id p97so51676426qge.1 for ; Mon, 23 Mar 2015 22:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Sw1Fjdsp9B2p+Pzg0gI59TH9bvpWYwSbKcFdDnmhVvE=; b=TRzuOFAG3aHk2D4E9VBXbXIWS5CltYc0JdW3z6zBmmAyesOUEndfNDUMjF30m2A/6b OFu9XpSgg7naMDk9yP8WUDPcasYi97fwfqckHJ+ZrEddfQHhC9h0Ovt3fhG7UQ9Ue7VT 7cAFIVLLL/ttsFuYm6ksMrhdAnpIveoTCziAMSGWaJU1DQCrQCQxqcUNRleq6f71GwcQ G5zjjbU6ke68SKdP00mhDLBLApafR85S5xBMXukDdkkrpSUTQcKP2PdSMHSQcU8QmJQ2 /RX5jC8XEyzKqW7jnY7onv352DLNjTTQ92xGS+h1nkMf9/eV2gYcXC2oFSxPdd6ehUYy ECRg== MIME-Version: 1.0 X-Received: by 10.140.147.66 with SMTP id 63mr3403773qht.35.1427175113953; Mon, 23 Mar 2015 22:31:53 -0700 (PDT) Received: by 10.96.39.195 with HTTP; Mon, 23 Mar 2015 22:31:53 -0700 (PDT) In-Reply-To: References: Date: Tue, 24 Mar 2015 12:31:53 +0700 Message-ID: To: Dmitry Stogov Cc: Xinchen Hui , Nikita Popov , Joe Watkins , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Use "ropes" for string concatenation From: pierre.php@gmail.com (Pierre Joye) hi! On Tue, Mar 24, 2015 at 5:41 AM, Dmitry Stogov wrote: > Hi, > > Recently, Xinchen and me worked on optimization that eliminates useless > reallocations and copying during string concatenation (ZEND_ADD_STRING and > family + ZEND_CONCAT). > > The idea comes from ropes, but adopted especially for our needs. > Rope is popular data structure in languages with immutable strings. > http://en.wikipedia.org/wiki/Rope_%28data_structure%29 > > We don't try to use ropes everywhere in the engine (at least it's too later > for 7.0), only for concatenation. > > The first branch uses ropes only instead of ZEND_ADD_STRING and family. > This must be safe. The only problem is possible memory leaks on exception > (but we already have this problem anyway). The simplest way to understand > the patch - read code for new opcodes in zend_vm_def.h. > > https://github.com/php/php-src/pull/1194/files > > The second branch in addition uses ropes for series of ZEND_CONCAT. It > disables calls to do_operation(ZEND_CONCAT) handler of custom internal > classes. > > https://github.com/php/php-src/pull/1195/files > > Both make slight speed improvement (first +0.3%, second +0.6% on wordpress > home page). > > We don't currently use ability to override CONCAT behavior in internal > classes, and I'm not sure if it may be useful at all. (For example Lua > doesn't provide concat meta-method). May be remove it? > > Thoughts and comments are welcome. Great work! :) Do you expect similar gain for other ops? I wonder if it would not be better to target 7.1 for that, adding it for other string operations, in one go. Most of the current patch is self contained, it adds quite some complexity to the engine for these operations only and it is not a small change at this stage (post features freeze). It sounds like a possible maintenance pain. Taking more time to actually experiment and implement this idea sounds safer to me (read: we have a bit less than a year to valid it then). Cheers, -- Pierre @pierrejoye | http://www.libgd.org