Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96498 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94175 invoked from network); 19 Oct 2016 18:58:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Oct 2016 18:58:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zeyos.com designates 89.163.237.165 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 89.163.237.165 mx.zeyos.com Received: from [89.163.237.165] ([89.163.237.165:35788] helo=mx.zeyos.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/0E-14749-D32C7085 for ; Wed, 19 Oct 2016 14:58:06 -0400 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id B88FE5FAC0 for ; Wed, 19 Oct 2016 20:58:02 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :to:subject:subject:from:from:date:date; s=dkim; t=1476903482; x=1477767483; bh=LQ9aybJ1y5xAuedJ6Ay/keu/R4GbXSTp544KYrSxsVE=; b= lLKVYKYUWrob1Z7AdKBZg79n/XhEmiz+F3nWMsZTyERZDcZ9vCiKpXzThWHbhnIq owd0oh3WtAMSGODSNZkZEwduwu/ocTyRJoSH3+1rNoXp01W8Zue0/gkQ9DZ4/SB3 bptlFr6ICIVFDFr5Y9BkJ/A901bvlk3CIsVCwiezlC0= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id RzVi9nheKk3c for ; Wed, 19 Oct 2016 20:58:02 +0200 (CEST) Received: from 127.0.0.1 (srv32.dedicated.server-hosting.expert [89.163.135.32]) by mx.zeyos.com (Postfix) with ESMTPSA id E9D875FABD; Wed, 19 Oct 2016 20:58:01 +0200 (CEST) Date: Wed, 19 Oct 2016 20:58:01 +0200 To: Dmitry Stogov , Xinchen Hui , Nikita Popov , Joe Watkins , Bob Weinand , Andrea Faulds Cc: PHP Internals MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20161019185802.B88FE5FAC0@mx.zeyos.com> Subject: Re: [PHP-DEV] Exploit fully packed array/hash property From: ben.coutu@zeyos.com (Benjamin Coutu) Hi Dmitry,=0A=0AOn second thought, I might have dismissed your HASH_FLAG_*_= KEYS idea prematurely. Of course we will have to set/unset the flag in parts of the code that are = very hot and naturally that will lead to a regression in terms of CPU instr= uctions. But in regards to your idea of possibly eliminating redundant chec= ks on every loop iteration, I think it could be interesting. It's a tradeof= f between maintaining the necessary flags and avoiding repeatedly iterating= over branches. Given that bitwise operations on these flags are just about= the cheapest operations the CPU can perform (no pipeline stalls and flags = usually already in L1 cache at that point), and branching inside a loop bei= ng extremely costly (with the risk of pipeline stalls caused by branch miss= prediction, which might even happen repeatedly, and EXPECTED/UNEXPECTED ma= cros undesirable in most of these cases), choosing to maintain those flags = on write operations in order to speed up read operations suddenly looks muc= h more appealing. In many operations that deal with the hash table in bulk = we might even be able to set the flag just once upfront. So maybe we should= investigate further. Your quick test is not conclusive because you have ef= fectively only benchmarked the negatives without settling it with the posit= ives.=0A=0AI don't know wether the additional code complexity is worth the = effort though. Personally I'd like to focus on getting more out of the pack= ed hash table case, meaning trying to preserve the packed characteristics a= nd utilizing dedicated code paths as much as possible throughout the entire= code base while using the existing infrastructure to do so without additio= nal overhead. Packed arrays are very ubiquitous after all, and as HT_IS_PAC= KED always implicates HASH_FLAG_LONG_KEYS, there is not that great of a nee= d for the latter if we can ensure to use packed arrays wherever possible.= =0A=0AOn another note, and this comes without any caveats, we could at leas= t use HT_IS_WITHOUT_HOLES to get rid of repeated checks for Z_TYPE(p->val) = =3D=3D IS_UNDEF inside loops. This would not entail any overhead on write. = What do you think?=0A=0ACheers,=0A=0ABenjamin=0A=0A=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Original =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0AFrom: Dmitry Stogov =0ATo: Benjamin Coutu , Xinchen Hui , Nikita Popov , Joe Watkins , "Bob Weinand" , Andrea Faulds =0ADate: Wed, 19 Oct 2016 18:02:53 +0200=0ASubject: Re: [PHP-DEV] Exploi= t fully packed array/hash property=0A=0AThis is an option.=0A=0AIf nobody p= ropose a better solution, I'll prepare the patch tomorrow (this solution wo= n't make BC breaks at all).=0A=0ABTW: I think, HASH_FLAG_*_KEYS may be used= to eliminate redundant checks on every loop iteration in some functions.= =0A=0AThanks. Dmitry.