Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126348 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 EA6731A00BC for ; Sat, 8 Feb 2025 11:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739014425; bh=r+UcUmOwxopiHBsBykxeX30ZcD/B/2kkhnrZ4tbMN6c=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lkuZkJqnUFyaCUXRg7wg8q6TXC+wo1jOUOR5IjwJOegW4Ly9mIzaL1R/KZpWXi1++ j4YoBE2wYeAtpINGTF/L7N7xk7xn5Itv5dChOtS85Ug2iGi55XQ+7w9fQC/sAo0vXx It1iWa99oW+XPvS0cZE74EKIa8VAD0cn6Qxy0DPfMGmZCv7HhetJx0EChw9JVUVhtb A4S7Nfa31nCupAGpMIuqtmvVL0mBd7dE9gb3W/hUubCozqX1QxY4IZn3mNGFNGG5jD ZJIPEe1FbMiwdCewp1GTadMPqDtS01xf3PnrrwltnuvAc24o7fIO3ggk8/tLTO2VOt Z9sjfWPdV3CPw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3278D180086 for ; Sat, 8 Feb 2025 11:33:44 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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, 8 Feb 2025 11:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1739014586; bh=mE7/rqUQwwZrmS80DAG82UIYdM3zDesWetMZHi4U7IA=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=lZc5rl749nkboxpGReQFu5oIhWU8OeJ4UQBjIvSTf9NywKvb4HCoZNwwVqEEO7O9l C+biH6vhz5Ii4O+ctFvQPE6sbrHwZJakYpcyPRXXk1GVElxwg7oUSPxhk3U3Q3Em1G AfDInXDB789+TaaK3bp7JxNf0OUYRKZanniRWh0FzLnEvNrSqtJYj9YvkpB6OVx2JM Q8n8UON01Qo4vc85yL/VPLReSIluRHmPdEpTG3eDK3awK94fL7pKnKz3Yl+hsm/JX0 YaaRUdoZmes+fxFKdwY+AQVC7E1Z7F6gsDpBfiD/g8cXilYorh/3O0b8e8Xm8G2K67 rgQi7RBERbBUg== Message-ID: <1b8840b9-5ae0-40db-8af2-521ac5888c7c@bastelstu.be> Date: Sat, 8 Feb 2025 12:36:25 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Pipe Operator (again) To: internals@lists.php.net References: <5a584219f120385e7e30f6d0a46cc108@bastelstu.be> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 2/7/25 22:04, Larry Garfield wrote: > I split pipes off from the Composition RFC late last night right before posting; I guess I missed a few things while doing so. :-/ Most notably, the Compose section is now removed from pipes, as it is not in scope for this RFC. (As noted, it's going to be more work so has its own RFC.) Sorry for the confusion. I think it should all be handled now. The “Introduction” section still talks about function composition rather than the pipe operator, I believe. >> 5. The “References” (as in reference variables) section would do well >> with an example of what doesn't work. > > Example block added. I don't understand that example. If I would write this as regular function calls it works fine. Did you mean to compare against: inc_print(['a' => 'A', 'b' => 'B']); i.e. ['a' => 'A', 'b' => 'B'] |> inc_print(...); ? If not, then you will need to expand on “breaks” which is a non-technical term. >> 9. In the “Why in the engine?” section: The RFC makes a claim about >> performance. >> >> Do you have any numbers? > > Not currently. The statements here are based on simply counting the number of function calls necessary, and PHP function calls are sadly non-cheap. In previous benchmarks of my own libraries using my Crell/fp library, I did find that the number of function calls involved in some tight pipe operations was both a performance and debugging concern, but I don't have any hard numbers laying about at present to share. > > If you think that's critical, please advise on how to best get meaningful numbers here. Not sure if I missed the dedicated performance section on my first read through the RFC or if it is actually new. It also claims: > The result is that pipe has virtually no runtime overhead. Which given your claim that “function calls are non-cheap” and combined with the intermediate closure for calls taking more than one parameter is contradictory. Generally speaking, if your RFC makes a claim (about performance), then it needs to back this up by evidence and not with feelings. Regarding the “How”: A hyperfine (https://tideways.com/profiler/blog/how-we-use-hyperfine-to-measure-php-engine-performance) comparison for a release build comparing: 1. An implementation based on regular function calls without intermediate variables. 2. An implementation based on regular function calls with an intermediate temporary variable. 3. A performance-optimized userland pipe operator implementation. 4. The pipe operator RFC. would certainly appropriate to gain a first insight. Having an OPcode dump to compare (1) against (4) would help gain more insights as to where the performance differences come from. > If the expression on the right side that produces a Closure has side effects (output, DB interaction, etc.), then the order in which those side effects happen may change with the different restructuring. That is a good point. I see you added a precedence section, but this does not fully explain the order of operations in face of side-effects and more generally with regard to “short-circuiting” behavior. An OPcode dump would explain that. Specifically for: function foo() { echo __FUNCTION__, PHP_EOL; return 1; } function bar() { echo __FUNCTION__, PHP_EOL; return false; } function baz($in) { echo __FUNCTION__, PHP_EOL; return $in; } function quux($in) { echo __FUNCTION__, PHP_EOL; return $in; } foo() |> (bar() ? baz(...) : quux(...)) |> var_dump(...); What will the output be? > but using the temp-var approach makes dealing with references easier I thought the RFC said that references were disallowed? Best regards Tim Düsterhus