Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108135 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22257 invoked from network); 15 Jan 2020 02:44:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jan 2020 02:44:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C51AB1804F2 for ; Tue, 14 Jan 2020 16:51:33 -0800 (PST) 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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 14 Jan 2020 16:51:33 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 9F08A22B5F for ; Tue, 14 Jan 2020 19:51:32 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 14 Jan 2020 19:51:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=60qm+2 /tHobGFNsXJFCh/OYU+/RLVpby7rVgjmgxdaU=; b=A0x1BdUh2MV6bsSOmkgtrN VBiiFAdT9yryb9Zs9e+1U4RxG+dyv5mcd8b7TAhdL4sHW/C21OvadCUAk6gDLalP +EC0AwFKMMfzaDnPLFKzCpwdTHbPplehDXHzFLpmFB6yO77t7ozunN8iMLO8Q7fP m7m2xoIQm97TdPMzukHEm72EjcgkE1Zn9zhuyyiMiPEMuru8Ny77TAzhZY85H4x9 TOtIYeaCPIIEvSnSoRmGH9EJFtVCjGHlOJmZwUKCnniNPkIAEAD2oJo3K6PjgDaB Y2te/XhFDAy3KEvAqS/RfV4kyeq9FksoCQ/+cahGfABe5eMmkZPaAOrXatahdPag == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddvgddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderreejnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggt hhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2F7EE14200A2; Tue, 14 Jan 2020 19:51:32 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-754-g09d1619-fmstable-20200113v1 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <2502e68d-a1bc-41c6-9763-8c0e2ac9e6f4@www.fastmail.com> Date: Tue, 14 Jan 2020 18:50:57 -0600 To: "php internals" Content-Type: text/plain Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Introducing_compile_time_code_execution_to_PHP_p?= =?UTF-8?Q?reloading?= From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jan 14, 2020, at 1:22 PM, Mike Schinkel wrote: > On Jan 14, 2020, at 1:10 PM, Larry Garfield wrote: > >> I get your concern about recursion, but if that kind of issue is really > >> a concern I don't see why we could not artificially limit recursion on > >> preload to a configurable amount, with 100 being the default? > > > > It's not recursion itself that's an issue. It's that the behavior of the code changes between preload and non-preload contexts in subtle, non-obvious ways. > > > > I don't mean a recursive function that runs during preload. I mean if a function that runs in a normal request is written recursively, it will fail at high recursion levels only if the file it is in was not preloaded. So whether or not foo.php was run through opcache_compile_file() changes when and how code in that file will fail. That's the situation we want to avoid like the plague, IMO. > > With respect, that feels like you are concerned about some real edge > cases, and ignoring the probability that most code run during > preloading would be written bespoke for preloading. I think you're still missing my point here. AST manipulation during preload would exist to manipulate code that would be run *later*. That's the point. Sure, the code in the run_once/preload/whatever block would be written to run in that context, but its entire point is, presumably, to improve the running of the *rest* of the code later. That's where the footgun exists. The recursion example was simply to demonstrate that even seemingly "safe" optimizations may introduce inconsistency, so I don't expect most userland developers to be able to get it right the first 5 times. (And again, I include myself in that.) > ALSO, I think I may have caused confusion by calling it "preloading." > In my mind that meant "run once" vs. "run for each page load" but I > think you are (rightly) conflating what I have called "preloading" with > the new preloading feature in PHP 7.4? > > What I have been envisioning is a `preload` (or some other) keyword > that we could apply to functions, methods, and expressions. When > `preload` modified functions/methods/expressions are reached during > OpCode generation, rather than generate a call to runtime code PHP > would just run the code and then take the return value and generate > OpCode for that return value. That... is a completely different thing, yes, that has nothing to do with the PHP 7.4 feature called preloading. Which would mean we've been talking about two different things this whole damned time. *sigh* > > That... sounds a lot like the new FFI extension? Write code in C or Rust or anything that can produce a .so file, plug it into PHP, go? > > Unless I am misunderstanding, using an .so requires a sysadmin to add > an extension and update php.ini. Which is a non-starter on hosted sites > like Pantheon, WPEngine, Kinsta, Pagely, Flywheel, PressLabs and > similar. No, the whole point of the FFI extension is that a user-land developer can load a .so file into PHP directly; basically doing the lib->PHP glue code in PHP rather than in C. It does require the FFI extension itself to be enabled, and to do safely requires using the preloader, which does mean setting an ini setting. Not all hosts support that. The one I work for does, which is why I've been playing with it lately to document it all for our customers. :-) But the fact that such advanced features are not universally available is... exactly why I am extremely cautious about having functionality that results in subtle behavioral differences between those environments where it's available and those where it's not. The existing preload logic has no impact on behavior other than skipping the autoloader. Any behavioral change is limited to those oddball libraries that do black magic during the autoloader, which are already well off the beaten path. That makes it a "safe" optimization. My underlying point, and then I will bow out of this thread as I am tired of repeating myself, is that I am all for enabling more "safe" optimizations, even letting userland developers build them, but we need to be extremely careful about them being "safe" and not "a time bomb that will introduce subtle behavioral differences between different run modes that a developer is not expecting, thus slowly creating libraries that will only function in one run mode or the other". If we can enable more optimizations while avoiding that trap, I'm all for it. But avoiding that trap is more important than giving developers more foot-guns. --Larry Garfield