Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85441 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6205 invoked from network); 24 Mar 2015 09:28:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Mar 2015 09:28:57 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.172 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.192.172 mail-pd0-f172.google.com Received: from [209.85.192.172] ([209.85.192.172:32840] helo=mail-pd0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/22-25887-85E21155 for ; Tue, 24 Mar 2015 04:28:57 -0500 Received: by pdnc3 with SMTP id c3so216039349pdn.0 for ; Tue, 24 Mar 2015 02:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=iyD/Ee28af8ud6U3eo3/g0CDLa8Af/UBDf5uB287lOI=; b=lo1NpESXAwzMYFLnbrJBkEmH5s9qz1/eO0cP8csOXXjDFzQSy4qBtBTb0W7sBUzBam gOEHscX/hOEcNwOQ5Hg2PGPqQD12xblY2KEqaWvjgkgk037nz9KIz7+bv2pSAef6jGbP xz7UwtQszuo/N+gVmdNPEBWxx/N3L3CyFoDt9rdoRSN17b9S3TphhIeLeI1D1+l0PiKZ QXPJrzBPHzMREfcNpeVMIGf17eDw4mnuqS5S2Iwa2+SmamI9NY3s8DP6rmCXWYsgDTcZ jVKZhL0PqpEIzNqsJ9bqwYMtzlY/FV+qjZfC5VYvFMKKjfLGiG5QtzlPbij7OARUR5HT Skhw== X-Received: by 10.66.248.200 with SMTP id yo8mr6006843pac.96.1427189334117; Tue, 24 Mar 2015 02:28:54 -0700 (PDT) Received: from [10.10.0.35] ([108.61.201.217]) by mx.google.com with ESMTPSA id ey1sm3550858pdb.30.2015.03.24.02.28.51 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 02:28:52 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-CC8DB9E7-BA19-4E33-BAFB-705AB1FCB7FF Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (12D508) In-Reply-To: Date: Tue, 24 Mar 2015 17:28:48 +0800 Cc: Dmitry Stogov , Xinchen Hui , Joe Watkins , PHP Internals Content-Transfer-Encoding: 7bit Message-ID: References: To: Nikita Popov Subject: Re: Use "ropes" for string concatenation From: laruence@gmail.com (Xinchen Hui) --Apple-Mail-CC8DB9E7-BA19-4E33-BAFB-705AB1FCB7FF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Hey Sent from my iPhone > On Mar 24, 2015, at 5:11 PM, Nikita Popov wrote: >=20 >> On Mon, Mar 23, 2015 at 11:41 PM, Dmitry Stogov wrote: >> Hi, >>=20 >> Recently, Xinchen and me worked on optimization that eliminates useless r= eallocations and copying during string concatenation (ZEND_ADD_STRING and fa= mily + ZEND_CONCAT). >>=20 >> 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 >>=20 >> We don't try to use ropes everywhere in the engine (at least it's too lat= er for 7.0), only for concatenation. >>=20 >> The first branch uses ropes only instead of ZEND_ADD_STRING and family. T= his must be safe. The only problem is possible memory leaks on exception (bu= t we already have this problem anyway). The simplest way to understand the p= atch - read code for new opcodes in zend_vm_def.h. >>=20 >> https://github.com/php/php-src/pull/1194/files >>=20 >> The second branch in addition uses ropes for series of ZEND_CONCAT. It di= sables calls to do_operation(ZEND_CONCAT) handler of custom internal classes= . >>=20 >> https://github.com/php/php-src/pull/1195/files >>=20 >> Both make slight speed improvement (first +0.3%, second +0.6% on wordpres= s home page). >>=20 >> We don't currently use ability to override CONCAT behavior in internal cl= asses, 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? >=20 > Overloading concat operator will be useful in the future for the implement= ation of the UString class, for example. >=20 then we can implement is in rope_end handler, and don't convert op to string= in rope add var handler. Thanks > Nikita --Apple-Mail-CC8DB9E7-BA19-4E33-BAFB-705AB1FCB7FF--