Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126033 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 28D5D1A00BD for ; Sat, 23 Nov 2024 15:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732376116; bh=XbWMMDJ+/JMG6j8CUv+Je5Ku48A11CUWAvxJM8VEYu4=; h=Date:Subject:To:References:From:In-Reply-To:From; b=mv8KednPBdayG3VTecHaNT5v3G3IPdao1SlXeWIORXMet+sxz5BDBPchSx4z0WmTP CrJpGaV38x7tudQMrMcMCd/1bNLlhckWN1PNHXZfQzgW98zP72zlVe0v+HLFe6gfc3 UI4ao0oK6rOSCgBFGB9VOs5NynbV/iVYq4U2shKzPdj5sK/Es0w//eGdvbsG0cCLdb 33XBKjW7CjjoH0qbE+57teL4UnoNHG5HPawbhAG3DsZZjJRbeuG/3Ax5EMKT2GTc5t opdUylby3T9FxsV9yXF9Qj+TDolbW/FxPcXwuAfZ/FosLP0gIZhAEBvaPvS0k3p9o1 RlIZWAqfBCsNQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 84D301801D8 for ; Sat, 23 Nov 2024 15:35:16 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 23 Nov 2024 15:35:16 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 09C471380247 for ; Sat, 23 Nov 2024 10:32:35 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Sat, 23 Nov 2024 10:32:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding: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=fm1; t=1732375955; x=1732462355; bh=iOJaofDsG9DC/KjKyGx5BpoPlZgAYlSm+07f1po6sGs=; b= ZbWnh/7goBVv6CcjVJp+bJVDP6d5HD8uOeLL9g8e8iVxzQ2S92hkaBSEiPD0wtT/ lelWaPV248sbGwKfCB+HTcluB/5W95myuAK6j2TSr+AcpZSd2uNcde8HbWAZ0aa1 J/l8NgVehjYiwWsEWe1MtYa7dzMoun3DTmFEXV6BAppj4Rxjw0Nhp8TgpmkWnkAT lUd8LVTk6nlRcSLU6R21yttdCZ8X23qVj4ZXKX1sVpghDlNCL/8S2lomV62V+CeT ShBx6jFWnVLvvjUdcAHumtFYslX1EL3Pakq8ugMzs/q045rRkxgCHkaH3+dR+Bs2 /3/b5MP5Y7XWPcN0ci/yug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender :x-me-sender:x-sasl-enc; s=fm1; t=1732375955; x=1732462355; bh=i OJaofDsG9DC/KjKyGx5BpoPlZgAYlSm+07f1po6sGs=; b=imC/iATBt/Kakve9L 172lfP7Trd9EaxTYGQmJhL0RGGwvRbgatssKwCPczzQdW39+b+w5dw8elIjy/4nb 7acVx+Vp0u+c4/j3hmD9RSlOPJl3jprIL711p1RoeY81hyGUxe23+8JwxX8Mybvt C428AXiGchgeieLXQWxZ3p0SzbISCu5gqmqjMdBSI116LL/79/E1cK/ToiXnVfsR zoJIfX+mvjolIdgXhRE0RSd14jwojL3uiTxzY3XwbcQ+5GbX27RvUhp2pcUR1pOH 4H6hMfv46/3DI8/62Wi0Q6XsUMCbogCkZcrJPlXTzP32FLpl86ZV9OUB9XZ3Mk4r DG4SA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrgedugdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuf fvfhfhjggtgfesthekredttddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhs ucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecugg ftrfgrthhtvghrnhepffekveduffduvdehjedvfeekleeftddugeefheejudehgeeiudff geeggeevfeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedu pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 23 Nov 2024 10:32:34 -0500 (EST) Message-ID: <97a3c02b-6711-45eb-93aa-640b6ecb263d@rwec.co.uk> Date: Sat, 23 Nov 2024 15:32:32 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Data Classes To: internals@lists.php.net References: <18b85ba5-5f1c-489c-9096-3ae203977fbe@app.fastmail.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 23/11/2024 15:02, Eugene Sidelnyk wrote: > If I remember correctly, the whole concept of "value" is fully > described in DDD book by Eric Evans. If that's the point of the RFC, I > wonder of there's any point in not making such classes immutable by > default, and to keep only one instance of value object unique per > given set of properties in memory, thereby eliminating cloning > altogether and optimizing the memory usage. As I mentioned on the "Records" thread, guaranteeing that every combination of values will exist exactly once in memory could create more overhead than it saves. Certainly if you write this, sharing memory makes a lot of sense: $arr = []; $i = 0; while ( $i++ < 100 ) {    $arr[] = new Point(0,0); } But if you instead write this, maintaining the cache will end up more expensive than just allocating each object/record/struct directly: $arr = []; $i = 0; while ( $i++ < 100 ) {    $arr[] = new Point($i, $i); } If the guarantee is copy-on-write, caching could be a compile-time optimisation; e.g. an OpCache pass might rewrite the first loop to the equivalent of this: $arr = []; $i = 0; $__cachedPoint = new Point(0,0); while ( $i++ < 100 ) {    $arr[] = $__cachedPoint; } The main thing that would prevent this optimisation is a custom constructor which might make the number of "new" calls observable. Either the optimiser would have to detect a custom constructor, or data classes / structs / records would have to prohibit defining one. -- Rowan Tommins [IMSoP]