Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117916 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37659 invoked from network); 12 Jun 2022 15:34:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 15:34:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1AC0A180384 for ; Sun, 12 Jun 2022 10:21:51 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Jun 2022 10:21:50 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 425263200786 for ; Sun, 12 Jun 2022 13:21:48 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Sun, 12 Jun 2022 13:21:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1655054507; x= 1655140907; bh=ujM2DwhD0+Co/GzNCn1J1tiadE9uJV5d1phhi/7nYlU=; b=h mpZSOFRDehRz1Y5JxRzLOY8cRj0GMd9rLI2Gq4eDCPLF94fAcdIF/H2l8Zv3DXFb vVP2SXeHZREPD/mnkHSIaqgl21YZK0GDvlG/SQqaBHTp28aquO/BdFp4N8WKqiPp +l22YCGeIn7PMdfY7lmbY7UHXjh/w87V71YncIs3tySlJMM5IP7lq4sS8xlGNdf1 KkEtR63LF5Tf+EdP5NdjTV5OtAO/bzTqZ/fgUyw/V4SInQGtb7WzO3OhnheGUXdG FdsJnr7rwu03ef9CUeE8en1uWBYSpX3ONAT9hWxB7M33Vp1htqmbxxGHCp/m8LNX 5HTVAdH6JRq5R3lcApjrQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1655054507; x=1655140907; bh=ujM2DwhD0+Co/GzNCn1J1tiadE9u JV5d1phhi/7nYlU=; b=KUe29arkc3Hrlkf+r9wK9auEzRfliC+JeiYNzz6o0qtU BLFgANsl019xZ0b1otncxwI0lEf5geRGgDmgcsWTd1RuRVtD8OR1FQRHUeUuyB8C WDAcHrO79L9KzAfgohetEluUXkkIEOb9V51R+/SpN3qfCNwD2UxhK383d87jBrI1 6UNUIVvpeSUFv+YiFJvDM+MWxM4oItrbJSik2HbibizL8D20/WD8/1QCABVkStp/ X6P7HmC/77IyU1sAdU1a29dvYCe7iDQvy4mOy94kGey4WL2htv0MH22E++4x67tt S01h+hTaeAez16/OY8oYnUUlthQfPmjVa062uaI2Yw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudduhedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepveehhedvveejledvvefgleevffdtjeekledvkeeg heffgfeivdejhffhledtudetnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6B574C6008A; Sun, 12 Jun 2022 13:21:47 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-692-gb287c361f5-fm-20220603.003-gb287c361 Mime-Version: 1.0 Message-ID: <2279cbd2-fcfe-460f-97f9-0029b7b043bb@www.fastmail.com> In-Reply-To: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> Date: Sun, 12 Jun 2022 12:21:26 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jun 9, 2022, at 11:34 AM, Larry Garfield wrote: > Last year, Nuno Maduro and I put together an RFC for combining the > multi-line capabilities of long-closures with the auto-capture > compactness of short-closures. That RFC didn't fully go to completion > due to concerns over the performance impact, which Nuno and I didn't > have bandwidth to resolve. > > Arnaud Le Blanc has now picked up the flag with an improved > implementation that includes benchmarks showing an effectively net-zero > performance impact, aka, good news as it avoids over-capturing. > > The RFC has therefore been overhauled accordingly and is now ready for > consideration. > > https://wiki.php.net/rfc/auto-capture-closure A little data: I used Nikita's project analyzer on the top 1000 projects to get a rough sense of how long-closures are used now. All usual caveats apply about such survey data. I was specifically looking at how many `use` statements a closure typically had, and how many statements it typically had. Mainly, I am interested in how common "really long closures where the developer is likely to lose track of what is and isn't closed over" are. Total closures: 20052 Total used variables: 11534 Avg capture per closure: 0.575 Avg statements per closure: 0.575 Used variable distribution (# of use variables => how many times that happens): 0 => 12833 1 => 4585 2 => 1667 3 => 591 4 => 198 5 => 98 6 => 43 7 => 16 8 => 9 9 => 6 10 => 2 11 => 4 Statement count distribution (# of statements => how many times that happens): 0 => 266 1 => 13134 2 => 2885 3 => 1598 4 => 818 5 => 429 6 => 284 7 => 176 8 => 125 9 => 88 10 => 48 11 => 58 12 => 25 13 => 27 14 => 14 15 => 16 16 => 13 17 => 7 18 => 3 19 => 7 20 => 4 21 => 5 22 => 3 23 => 2 24 => 3 26 => 2 27 => 1 29 => 1 30 => 1 35 => 1 36 => 1 42 => 1 44 => 1 48 => 1 59 => 1 69 => 1 103 => 1 122 => 1 Analysis: * The bulk of closures close over nothing, so are irrelevant for us. * The bulk of closures use only one statement. That means they could easily be short-lambdas today, and are likely just pre-7.4 code that no one has bothered to update. * The overwhelming majority of the rest are 2-3 lines long. The dropoff after that is quite steep. (Approximately halving each time, with a few odd exceptions.) * Similarly, most `use` clauses contain 1-2 variables, and the dropoff after that is also quite steep. * There's some nitwit out there writing 122 line closures, and closing over 11 variables explicitly. Fortunately it looks like an extremely small number of nitwits. :-) The primary target of this RFC is people writing 2-4 line closures that import 1-2 variables, both easily small enough that there should be very little risk of developers getting confused by their own code. Based on the data above, I conclude that group is very much the typical case for closures already, and thus the risk of this syntax resulting in harder to follow code where developers get confused about what is imported and what isn't is very low. --Larry Garfield