Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85438 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3004 invoked from network); 24 Mar 2015 09:11:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Mar 2015 09:11:22 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.173 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.173 mail-we0-f173.google.com Received: from [74.125.82.173] ([74.125.82.173:36739] helo=mail-we0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/81-25887-93A21155 for ; Tue, 24 Mar 2015 04:11:21 -0500 Received: by wetk59 with SMTP id k59so158096590wet.3 for ; Tue, 24 Mar 2015 02:11:18 -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=kXtYMnTRZo8s4KP02GWfg/IZXQu2MJcbKzQNoxDK30s=; b=O4+XtYjDi/CSPdZC7E87a8VzFIghBBmFmtbIVvVj8RXTxHMP7IPRITjJHQwa8o5Ckv djMECQ40U6xMAY1VIRglg7GiqJkmPN07rLwMX2A0GPfyjeKt9MohAfEFpNAR/qJjb5jy GL2aBi9NdOPGE0ab2MYsO1qKgLE70yIk1mD3t0masDtZupk/4cAHXrpNBGm7H/7l5yM5 YzGEhhCKMyRQw6mw3If8K3hKmEkeJkj/pNqtx0cCnLs+DatVUXxG62GLSkfCPadY2vrt FV6QQEoNu2tZKMVGhWy3jR/jQ2HMWDeeSgCYpMUJZyv1t97NMmW9Fjf9K7IacLZqtG+/ kEKQ== MIME-Version: 1.0 X-Received: by 10.180.104.33 with SMTP id gb1mr26306409wib.33.1427188278492; Tue, 24 Mar 2015 02:11:18 -0700 (PDT) Received: by 10.27.10.193 with HTTP; Tue, 24 Mar 2015 02:11:18 -0700 (PDT) In-Reply-To: References: Date: Tue, 24 Mar 2015 10:11:18 +0100 Message-ID: To: Dmitry Stogov Cc: Xinchen Hui , Joe Watkins , PHP Internals Content-Type: multipart/alternative; boundary=f46d0442678e5e049d0512052ad0 Subject: Re: Use "ropes" for string concatenation From: nikita.ppv@gmail.com (Nikita Popov) --f46d0442678e5e049d0512052ad0 Content-Type: text/plain; charset=UTF-8 On Mon, Mar 23, 2015 at 11:41 PM, 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? > Overloading concat operator will be useful in the future for the implementation of the UString class, for example. Nikita --f46d0442678e5e049d0512052ad0--