Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80059 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52387 invoked from network); 1 Jan 2015 16:54:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jan 2015 16:54: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.175 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.175 mail-vc0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:64743] helo=mail-vc0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/0F-60454-2CB75A45 for ; Thu, 01 Jan 2015 11:54:27 -0500 Received: by mail-vc0-f175.google.com with SMTP id hy10so6589009vcb.6 for ; Thu, 01 Jan 2015 08:54:22 -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=lOy7faTyiaePXnBYPCuNaUJNxZQt1iiX/y+jn0tEDBU=; b=IQsZY4tWMGILP8oiDMF+jX6zFtw/WzOF6j0gjcfhmOzkkV+EVkaIjtg6sJbPpoCVAL ZeEH9I75Kgqm4xbO6wMjbXMPmUiDz3W5fFANNE2bDMtjaLtW7xDPU0OOysKWIKRJwyeS Anhp5BGyhTFl3T5ugNvTY+CCFDC95fQX201Fz/5rV4iQToGJfstOOhaAC6euDuQC6dW8 gW9vYEb/L9Gb0Q9McyhrjyGFp6U53AYR1FcbHoGbHC2+XQQxaWjyUJ5aFe03V6abFL+S 3OOLyU5k+fLxrQ5JPMQ5dLktvLj6lI62nTGs6+0hW93yCFPqpPpz0uahe5vHI+CAYfGR hGzQ== X-Gm-Message-State: ALoCoQlrLGiIFwTWRfzqzqjFnBYzYGVG12VmOMB2deTSXxz6b4Ey+nZ5TwxIsTkTOAt7TF9tWkdrHzol0i5pDwmime+J7pecyQdVbWtJUXuR08gPTFCX/fV6aGE99Oiq3j6p6SNz7uurw8t1keQlMZdzyuaTH8oGXg== MIME-Version: 1.0 X-Received: by 10.221.28.67 with SMTP id rt3mr34476899vcb.33.1420131260002; Thu, 01 Jan 2015 08:54:20 -0800 (PST) Received: by 10.52.26.40 with HTTP; Thu, 1 Jan 2015 08:54:19 -0800 (PST) Received: by 10.52.26.40 with HTTP; Thu, 1 Jan 2015 08:54:19 -0800 (PST) In-Reply-To: References: Date: Thu, 1 Jan 2015 20:54:19 +0400 Message-ID: To: Nikita Popov Cc: PHP Internals , Xinchen Hui Content-Type: multipart/alternative; boundary=001a11333a4c499141050b9a131f Subject: Re: Merge HashTable and zend_array into a single data structure. From: dmitry@zend.com (Dmitry Stogov) --001a11333a4c499141050b9a131f Content-Type: text/plain; charset=UTF-8 Hi Nikita, On Jan 1, 2015 5:23 PM, "Nikita Popov" wrote: > > On Wed, Dec 31, 2014 at 11:19 AM, Dmitry Stogov wrote: >> >> Hi, >> >> Please take a look into the patch >> >> https://github.com/php/php-src/pull/970/files >> >> This real changes are in zend_types.h, the rest is renaming that in most cases makes code cleaner. >> >> zend_array didn't change its binary representation, but now it's not possible to get a pointer to embedded HashTable. The same zend_array shoukd be used instead. >> >> Each HashTable got an extra 64-bit zend_refcounted header. This leads to some increase in memory consumption. > > > In your patch zend_hash_init (and zend_hash_destroy as well) ignores the refcounted header. So currently you wouldn't be able to use just any HashTable* in a refcounted way (e.g. do an object->array cast by adding a ref to the properties HT and sticking it in a zval). You can only do the reverse, i.e. use a no longer used refcounted array somewhere else (like the way properties are assigned in pdo/... now). > > What's the plan about this? Is this intentional or will the hash API start managing the refcount as well (like strings already do)? you are right. It must be fixed in some way. we may start playing adding assert(refcount == 1) in all zend_hash functions that modifyes HashTables. Other ideas are wecome... > >> >> The performance is slightly increased (may be measured with callgrind). >> >> The patch beaks one test (tests/lang/foreachLoopObjects.006.phpt), but actually it just disclose a problem that we have anyway. >> >> The patch should be a base for the future optimizations. e.g. removing HashTable->arData and/or HashTable->arHash and allocating them together with zend_array; introducing EG(empty_array) etc. > > > Could you elaborate on the first part? How is it possible to alloc arData/arHash together with zend_array? (Or rather, if you do that, how can you change the size later?) We may reallocate zend_array itself. Of course, it would require using zend_array ** in all functions that may modify it, and also using zend_array* instead of embeded HashTables. Thanks. Dmitry. > > Nikita > --001a11333a4c499141050b9a131f--