Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95988 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62201 invoked from network); 13 Sep 2016 16:30:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2016 16:30:07 -0000 Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; 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:53244] helo=mx.zeyos.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/01-60695-C8928D75 for ; Tue, 13 Sep 2016 12:30:06 -0400 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id D68A15FA84 for ; Tue, 13 Sep 2016 18:30:00 +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=1473784200; x=1474648201; bh=td0gB+nEyRXZjrFNG4oRihRmGNsfP5FiHlOWVYXXTOk=; b= lGc5t+x/QvS3jWoNi1iO8sNN1IrPsmxBH9SSSga3ZWm7M++IM9sxb1Z1nu5Edkms B7LkzcQx6v/ooiGCv5KRv2+9H3KPJGS42f3fzEBGoAgy4kZ1GTp/CSHr+HxXfgjQ p9++lgt0ZyBIz8yUYTDP5fgdkAOMDHHIN3BME/+bOhA= 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 Dbe0mJGggJ3B for ; Tue, 13 Sep 2016 18:30:00 +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 4FEA85FA7A; Tue, 13 Sep 2016 18:30:00 +0200 (CEST) Date: Tue, 13 Sep 2016 18:30:00 +0200 To: Nikita Popov , Dmitry Stogov , Xinchen Hui Cc: PHP Internals MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20160913163000.D68A15FA84@mx.zeyos.com> Subject: [PHP-DEV] Directly embed small strings in zvals From: ben.coutu@zeyos.com (Benjamin Coutu) Hello everyone,=0A=0AI was wondering if it would make sense to store small = strings (length <=3D 7) directly inside the zval struct, thereby avoiding t= he need to extra allocate a zend_string, which would also not entail any co= stly indirection and refcounting for such strings.=0A=0AThe idea would be t= o add a new sruct ``struct { uint8_t len; char val[7]; } sval`` to the _zen= d_value union type in order to embed it directly into the zval struct and u= se a type flag (zval.u1.v.type_flags) such as IS_SMALL_STRING to destinguis= h between a regular heap allocated zend_string and the directly embedded co= mpact representation.=0A=0ASmall strings are quite common IMHO. In fact qui= ckly sampling my company's PHP code base I found well over 50% of the strin= gs to be of length <=3D 7. It would save a lot of memory allocations as wel= l as pointer indirection, and could also bypass refcounting logic. Also, co= mparing small strings for equality would become a trivial operation (just c= omparing two pre-aligned 64bit integers) - no more need to keep small strin= gs interned.=0A=0AOf course it wouldn't longer be possible to also persiste= ntly store the hash value of a small string, though calculating the hash va= lue for small strings is less costly anyways because less characters equals= less iterations, so that might not be an issue in practice.=0A I don't see such an idea in https://wiki.php.net/php-7.1-ideas and I was wo= ndering: Has anybody experimented with that approach yet? Is it worth discu= ssing?=0A=0APlease let me know your thoughts,=0A=0ABen --=20 Bejamin Coutu ben.coutu@zeyos.com ZeyOS, Inc. http://www.zeyos.com