Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85428 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52008 invoked from network); 23 Mar 2015 22:41:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Mar 2015 22:41:14 -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.160.178 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.160.178 mail-yk0-f178.google.com Received: from [209.85.160.178] ([209.85.160.178:36133] helo=mail-yk0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/60-48509-88690155 for ; Mon, 23 Mar 2015 17:41:12 -0500 Received: by ykcn8 with SMTP id n8so80363878ykc.3 for ; Mon, 23 Mar 2015 15:41:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=6YYLAppTdCNKqhhTaMYqBb+jxfyNpnS7jeuLfagxYFI=; b=mlvutbmjm5Kl5CN5vjUqZGEe2lcixXpV76d9/cTUS5IGa+oboeuQQFzGhi/r+TcDGs gknMccQMYNV1QjGaWL1hieOIS+hCxQfCsDoDoCxBhwvs52wTFw4Q36dyTuO0mRhbEPUN 8c6LLLD81SAx8JeXXbxPajWRjPC+y9MHjFDfKNo/IikD5UhWjGBbE+GkyE7LWO8QGiCu TYHxcmek0k/P9QpAW1SruAWTjE+L+wNe5uFtd0UT6MdxSQZKN9qxIQWkKUfWSnLPo6wH 5ZpAwXEWsNHTCoUVcobyv1iVQqnXLEg2om0MJoYYNkdCbN0lmj14WnAHQB351JDdFBkf 8eAQ== X-Gm-Message-State: ALoCoQlRSIRILUGdsM/mfECsOXYqJ+6GSmie60JIm8PkVWBvoo75Fra9oVZTlhbsuKAx3TqVEQBPIBY8yTe2COMjfCqBMsrr9oDHtS5d7TXxD29jQY3kY8rCsCmTIShEgX63OYJK5LGmzZU0b3gM1x3qHgsR+aznnA== MIME-Version: 1.0 X-Received: by 10.52.165.65 with SMTP id yw1mr1072323vdb.51.1427150468198; Mon, 23 Mar 2015 15:41:08 -0700 (PDT) Received: by 10.52.248.36 with HTTP; Mon, 23 Mar 2015 15:41:08 -0700 (PDT) Date: Tue, 24 Mar 2015 01:41:08 +0300 Message-ID: To: Xinchen Hui , Nikita Popov , Joe Watkins Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c29cc0b2cd410511fc5cb0 Subject: Use "ropes" for string concatenation From: dmitry@zend.com (Dmitry Stogov) --001a11c29cc0b2cd410511fc5cb0 Content-Type: text/plain; charset=UTF-8 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. Thanks. Dmitry. --001a11c29cc0b2cd410511fc5cb0--