Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101111 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40963 invoked from network); 8 Nov 2017 19:26:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2017 19:26:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=thruska@cubiclesoft.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=thruska@cubiclesoft.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain cubiclesoft.com designates 149.56.142.28 as permitted sender) X-PHP-List-Original-Sender: thruska@cubiclesoft.com X-Host-Fingerprint: 149.56.142.28 28.ip-149-56-142.net Received: from [149.56.142.28] ([149.56.142.28:47418] helo=28.ip-149-56-142.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/77-15386-54A530A5 for ; Wed, 08 Nov 2017 14:25:59 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id 563933E879 To: bishop@php.net Cc: PHP Development References: Message-ID: <5439c955-5290-565c-db07-28a066d998b9@cubiclesoft.com> Date: Wed, 8 Nov 2017 12:17:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Inserting string keys in arrays at any position From: thruska@cubiclesoft.com (Thomas Hruska) On 11/3/2017 7:46 AM, Bishop Bettini wrote: > On Fri, Nov 3, 2017 at 9:51 AM, Thomas Hruska > wrote: > > http://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.html Ah. Very clever and cool. That memory layout does indeed pose a problem with random order insertions of string keys. Detachable nodes are more useful to me in C++ for a general-purpose data structure but I can see the benefits of doing this for PHP 7, which takes advantage of the most common array usage patterns (i.e. an array). After reading that post, I was inspired to implement PackedOrderedHash: https://github.com/cubiclesoft/cross-platform-cpp I can definitely see why PHP 7 adopted the structure. My own benchmarks of PackedOrderedHash show significant performance improvements. You'll note that in PackedOrderedHash I excluded inserting just anywhere - likely for the same reason that PHP doesn't offer such a feature. I still think PHP could natively offer string key-based insertions even though it'll require moving elements of an array around. That's likely to be faster than rebuilding the whole array. Thanks for the long writeup and Nikic for the blog post. -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/ And once you find my software useful: http://cubiclesoft.com/donate/