Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123759 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 4A3CF1A009C for ; Sat, 22 Jun 2024 20:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719089383; bh=Y4nvaYNkXOYIv2djakJZkNohUxetk+qu9KLTLTTfCPk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=BCgnEItU0YcgyFw1+wIiNvgvvqwTKRL1uPk6jo21OSuOWel61E/PyKL3GQXSmOPAr 4sW7Qdk+ER1FW41btQ0UArw7KpIq2hfN6b/TeU50BJSHo4xrpKBBYjIy0YhR2aI/kw XopbdgFXPAGlhVbOr25V+KBHYij0O3fMWIZtpmhD+GCVxEYPrKBuMRHYYJEtHQSEvw htLLONAHL4kceeYxhJHWKEhA6EhllNkpgnZwOQp+2aHoEwdoRngVwbiOC2a2MaZeRp EkT2/frIdySre5UxYXxEc0sRI+F5K7DhfolyWug2tN8WeKMyEo9n7OjsIjFJ84FraS 3XPAVHcg+Td6g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DDCE4180BE8 for ; Sat, 22 Jun 2024 20:49:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 22 Jun 2024 20:49:41 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 89D8A1140126 for ; Sat, 22 Jun 2024 16:48:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sat, 22 Jun 2024 16:48:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1719089305; x=1719175705; bh=4cInPULENJ EBniDKQWFzBZp1Mcla9KEFq8Un1i01SfM=; b=OREgjHFqzCeRM3ljTjmdTCgOcH X783Ax6Vq7TlPVGmmXPtlXYLdPIGnIOOuYlz1vxmjxvG0boACs/o9Wki1yIA5Yuw so/5V5sJcODuhABDLr+E51MxdTJ3Lkjl+KFpBmmSdu3J5Lh0u1eveWYQYMgsVLgC Pls0oMOjq74Mxqyk1RgThNYOp84ENrNr4VHLpBPUMZQNgq3vXRStXZNeTJYyBxvJ MbzcRg5Sk3ijNtl8/C/L47ybnenjiupQMgAOjCvS6qi+InGAGYELUDN4P6jXP1NA R+igxWJTBomgmfcSmIZvnweFof7iJjI714zKAbexV8jvTk45nUEot+tkP5Vg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719089305; x=1719175705; bh=4cInPULENJEBniDKQWFzBZp1Mcla 9KEFq8Un1i01SfM=; b=iOubq8D0Opc+NUQz+0IjIzYj+PG81XFkYXGTrC2Ig0Hn 0guY5aTSL8vdde6DqwtKYjPO3vwMfH88lgBSdLI5G0UQhG/URqu+8Q0C/wF4XzZR wxS4FsyZK6nGobL4kmdpVI6NQc8VJq12uoepnrsORspbhqWtFOAEJZWDJygSaeLX QwmmJyLRWX6k4/7AKgBwU7W8jY3ro2KSmO365UnjGWv/ExGGt3Knrwxkg1WtDbyC OVsUP2WZjbA5StXv73lmJiEMoXKnrNtKxmQ/37wPuCtTpWayJTXs/7rM6SCfmMOC g+5xxQbZ91ssxFLyAdeYwAY5d//d3tzk3WOwTRdABw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefiedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtd erredtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe ejvdefheekhfegleevudfgvdfhleegleeufeffteegfeefudfhtefghfefjeehhfenucff ohhmrghinhepnhhpohhpohhvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 22 Jun 2024 16:48:24 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------D9WAVzhUJ3Ekpb0TIDSxJPvg" Message-ID: <2d796f4f-d6c2-4ae6-aa2b-a281a0768e99@rwec.co.uk> Date: Sat, 22 Jun 2024 21:48:23 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: internals@lists.php.net References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <02ee8831-43a0-4857-886e-7f54fb42a99d@varteg.nz> <7d825b1d-e584-4916-9435-3561b9c54c26@gmail.com> Content-Language: en-GB In-Reply-To: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------D9WAVzhUJ3Ekpb0TIDSxJPvg Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 22/06/2024 21:15, Robert Landers wrote: > To me, that sounds kinda silly. PHP does reference counting and while > there is an overhead, it doesn't prevent us from using it... The reference count is a single pre-allocated integer on the C struct holding the value; and even then, a lot of effort was put in during the "PHP-NG" project (which landed in PHP 7.0) to avoid reference counting values that didn't need it. (Nikita wrote a great post explaining the changes here: https://www.npopov.com/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html) The problem with type counters is not just that there's more than one per array, it's that there's a *variable* number, so you can't preallocate memory for them, they need to reference some extra resizable hash-table. That's the "indirection" that Arnaud is talking about. I've thought in the past about caching type checks that had passed, so that a series of array checks could be made "for the price of one" if the array didn't change between. That might at least mean the additional table of types would only need accessing on type checks, not every write, but a lot of checks would still need to iterate the whole array. Having a structure that only allows one type could potentially be much more efficient, because you only need to allocate space for the type identifier, and check against it on write. -- Rowan Tommins [IMSoP] --------------D9WAVzhUJ3Ekpb0TIDSxJPvg Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 22/06/2024 21:15, Robert Landers wrote:
To me, that sounds kinda silly. PHP does reference counting and while
there is an overhead, it doesn't prevent us from using it...


The reference count is a single pre-allocated integer on the C struct holding the value; and even then, a lot of effort was put in during the "PHP-NG" project (which landed in PHP 7.0) to avoid reference counting values that didn't need it. (Nikita wrote a great post explaining the changes here: https://www.npopov.com/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html)

The problem with type counters is not just that there's more than one per array, it's that there's a *variable* number, so you can't preallocate memory for them, they need to reference some extra resizable hash-table. That's the "indirection" that Arnaud is talking about.

I've thought in the past about caching type checks that had passed, so that a series of array<int> checks could be made "for the price of one" if the array didn't change between. That might at least mean the additional table of types would only need accessing on type checks, not every write, but a lot of checks would still need to iterate the whole array.

Having a structure that only allows one type could potentially be much more efficient, because you only need to allocate space for the type identifier, and check against it on write.


-- 
Rowan Tommins
[IMSoP]
--------------D9WAVzhUJ3Ekpb0TIDSxJPvg--