Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80954 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56712 invoked from network); 22 Jan 2015 06:49:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jan 2015 06:49:22 -0000 Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.52 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.192.52 mail-qg0-f52.google.com Received: from [209.85.192.52] ([209.85.192.52:63208] helo=mail-qg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/91-44026-17D90C45 for ; Thu, 22 Jan 2015 01:49:21 -0500 Received: by mail-qg0-f52.google.com with SMTP id z107so16759248qgd.11 for ; Wed, 21 Jan 2015 22:49:18 -0800 (PST) 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=ST2gpSHux8/sS0adXANMokK7Tg03Wd2BWvAXZjxIJt0=; b=adHnwz+ce1F6dL1gjHCeMjoQf6umF63/olJjI8mjYKb+7JcTVSytNkqEwc4n0HSAUA On+ufjDoJUCxfoqQpQGlb/waCht3Tl+d9dhjDmJzpUjUaGIoiBFpqD7BJxNgNJbXmz0w gvSBm8p8ZlvYOl5yunOxPiBJ3XF386cRg5WfguAJKzZUbVZMdbT+nEp776njw9pbZMPu PzsOSBR77LP+yO4K06E/MBhvMBq64B0lmznHAhJVtFd5nAeIEuifV+9lc6QhReZ2ECAU nnhHfn9NjgalL5bZa2md4RGGqZtA9zmVPPr4+Za7tIx5rvhR+wfhqn73xGlCCry4xTAL FW9A== MIME-Version: 1.0 X-Received: by 10.224.11.5 with SMTP id r5mr77552400qar.10.1421909358781; Wed, 21 Jan 2015 22:49:18 -0800 (PST) Received: by 10.229.174.6 with HTTP; Wed, 21 Jan 2015 22:49:18 -0800 (PST) Received: by 10.229.174.6 with HTTP; Wed, 21 Jan 2015 22:49:18 -0800 (PST) In-Reply-To: <20150122064308.3877D5F8EC@mx.zeyon.net> References: <20150122064308.3877D5F8EC@mx.zeyon.net> Date: Thu, 22 Jan 2015 06:49:18 +0000 Message-ID: To: Benjamin Coutu Cc: Nikita Popov , PHP Internals List , Dmitry Stogov , Xinchen Hui Content-Type: multipart/alternative; boundary=001a11c2c01e3babfb050d381238 Subject: Re: [PHP-DEV] Improvements to Hastable Bucket structure From: dragoonis@gmail.com (Paul Dragoonis) --001a11c2c01e3babfb050d381238 Content-Type: text/plain; charset=UTF-8 On 22 Jan 2015 06:43, "Benjamin Coutu" wrote: > > Hi, > > Currently a hashtable bucket has to store both, the numeric index "h" and a potential pointer to a string key "key". > > There is room for improvement here because "h" and "key" are conceptually mutually exclusive. I therefore propose to unionize "h" and "key" to effectively save the overhead of having to reserve space for both. This conceptually makes sense if you I deed just need one or the other but not both. Have you implemented this yet ? Have you benchmarked it ? > > Now, in order to still be able to distinguish between an integer key and a pointer to a string key, one could use either of two approaches. > > === 1. Use flags of embedded zval (maybe _zval_struct.u1.v.*) === > > If the is-key-flag is set in the embedded zval then its a string key, if not then its an integer. This is of course only possible if _zval_struct.u1 is usable for this (I could not quickly tell). > > === 2. Pointer tagging === > > On a 64/32-bit machine all pointers will be aligned to 8/4 bytes meaning that their last 3/2 bits will always be zero. We can exploit this to effectively store information about the pointer in those bits. > > We will use the last bit to distinguish between a pointer and an 63/31-bit integer, and the second last bit to distinguish between a pointer to a string key or pointer to the overflowing integer (64/32 bit). Here is a (8-bit) sample: > > LLLLLLL1: integer (effectively 63/31) > PPPPPP00: pointer to zend_string (string key) > PPPPPP10: pointer to zend_ulong (in case integer key is > 63/31 bit) > > One will then be able to use simple shifting and bitwise operations to extract the correct meaning. > > Please let me know your thoughts! > > Cheers, > > Ben > > -- > > Benjamin Coutu > Zeyon Technologies Inc. > http://www.zeyos.com > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --001a11c2c01e3babfb050d381238--