Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125184 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 E4DFE1A00BD for ; Sat, 24 Aug 2024 17:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724519034; bh=dbyHMI7EHKIvnIPrmz8eG4Hdi+cI6LgJaHCPh2JNsew=; h=References:In-Reply-To:From:Date:Subject:To:From; b=mdb2pt6FSFouPGmt7qpzMP4t9vTtVS5XASu6JoDUSWimFcKAD8ERdMSUC++ZD1ObY 1gzde9E5zWAAI5Yp/s4WzbDBnoPvYomjTpb8YSK8S6Bhadi+0HMHAoFi17zijDMs/Q 9u9luABib+PVl9oqc1px3h/LDiUzbE9deuWcfVGZI5aRAwU39s4HjYfA4ys+YFg1I2 4izqTe1Z5yvw1Fv1ytwNo2w5dDh/xrboKmfR+b8f+JXCHZOBkGmj5A6Mth9ANcWwZm jnYkYPqXQn9xZpkQZNM4Lh4sOhr5Ru6nw41/J2Nch8sxa46LzzvxAErw6TgBSRVTML wy0aazLlajDig== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 94492180034 for ; Sat, 24 Aug 2024 17:03:53 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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, 24 Aug 2024 17:03:53 +0000 (UTC) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5dcad9845b4so2470023eaf.2 for ; Sat, 24 Aug 2024 10:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724518920; x=1725123720; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dbyHMI7EHKIvnIPrmz8eG4Hdi+cI6LgJaHCPh2JNsew=; b=ZbkkTkqnWbCP07fPNAxOoShgkjZiJ3Cw6vRuwUkrM4o2BRJ4ThHnKPr+noD0ULuAXA +AaNB9SX84XJCigd+rickfmVlPrdmze8xC6FUt/3EAzh74OaogeF1cbrmUFZ/H0GWUh2 SGqE+jVM7NUN+MImPzhoeLJb1e18tGUzlHabWkoP7zdfiAB800mNEgtMms4fs4fAeTad 8iVJdASdP2Hx1pBGoXco3J/2Pth+CIMLYVUNZyR8wNTlO+Tm/8sb1rmcItksfwgfOkOP apCechUaQYXZDSFhJ+AUuDJrga8IM5Vqv/yqxHBdry+ZtCpjCpVdGvXVbOBjRFZElyqe u7ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724518920; x=1725123720; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dbyHMI7EHKIvnIPrmz8eG4Hdi+cI6LgJaHCPh2JNsew=; b=RPMLFNJoyDX0kA/P6BL+UbRK31adu8QO5hhQz/JomqxZvp1GyQBlDz0sLA4VWBEgXO UwnQ+DBrWS/YxT8U59RsiiLD5tWn33CMkchVs+J9ZJ5rZJAYKLlg5PcaWyLuMsw1AQSD McsjpiIhLPN5YRDp1fBHJ00LY95bw1F4zAFRSh3xsCK7LvZOM9rrzVl/usUpcrg4FhAR gT6fa3SLDFyBqYr6aoZEF0LQ74aHpahglUuk0s9FGWDZipzkK0QDNlcyC3ol+E/pU2we me3w7nXpCF4CfNzBl3OF7jXi+V/zLbIGypzc/4GurUtlmbYZncsQ7dj+HXy6Cj6G/6zo fWdw== X-Gm-Message-State: AOJu0Yxc4oolcVGN1e76tdCdFGI8DWbKxL1ote/uEBwRPd6YsYoVcrT7 Jb2OpTVp6A001r7mA3Hzr6M67MzXNI8X9Sl+HEEw6vEhelrOPL01A+Rnh7PD9oBNy9h8d6EBVEo 54gC80Is+CKaa+8o434fdKQI0AKgnrMX3CYHRoQ== X-Google-Smtp-Source: AGHT+IHw78W/E2iZV/GcwZvrNMYmXeFoPj0ALXxbCw4nQ5sUx93NVJzRHd96S7+5+6FteuoHUHsvMmUkPvpvKoUwKNE= X-Received: by 2002:a05:6820:2228:b0:5ce:d2e3:b18 with SMTP id 006d021491bc7-5dcc62f93bcmr5656185eaf.8.1724518920417; Sat, 24 Aug 2024 10:02:00 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <181C78B1-65AD-44B4-AD95-A59791B7FF86@koalephant.com> In-Reply-To: <181C78B1-65AD-44B4-AD95-A59791B7FF86@koalephant.com> Date: Sat, 24 Aug 2024 19:01:48 +0200 Message-ID: Subject: Re: [PHP-DEV] [Concept] Flip relative function lookup order (global, then local) To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Stephen On Sat, Aug 24, 2024 at 1:54=E2=80=AFPM Stephen Reay wrote: > > Thanks for clarifying. Out of curiosity, how much optimisation do you ima= gine would be possible if the lookups were done the same was as classes (ie= no fallback, names must be local, qualified or imported with `use`)? I haven't measured this case specifically, but if unqualified calls to local functions are indeed rare (which the last analysis seems to indicate), then it should make barely any difference. Of course, if your code makes lots of use of them, then the story might be different. That said, the penalty of an ambiguous internal call is much higher than that of a user, local call, given that internal calls sometimes have special optimizations or can even be entirely executed at compile time. For local calls, it will simply lead to a double lookup on first execution. > I am aware this is a BC break. But if it's kosher to discuss introducing = a never ending BC break I don't see why this isn't a valid discussion eithe= r. It would give *everyone* that elusive 2-4% performance boost, would reso= lve any ambiguity about which function a person intended to call (the claim= ed security issue) and would bring consistency with the way classes/etc are= referenced. From my analysis, there were 2 967 unqualified calls to local functions in the top 1 000 repositories. (Disclaimer: There might be a "use function" at the top for some of these, the analysis isn't that sophisticated.) I also ran the script to check for unqualified calls to global functions (or at least functions that weren't statically visible in that scope in any of the repositories files), and there were ~139 000 of them. It seems like this is quite a different beast. To summarize: 1. Flipping lookup order: ~a few dozens of changes 2. Global only: ~3 000 changes 3. Local only: ~139 000 changes While much of this can be automated, huge diffs still require reviewing time, and can lead to many merge conflicts which also take time to resolve. I would definitely prefer to go with 1. or potentially 2. Ilija