Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108108 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 685 invoked from network); 13 Jan 2020 09:32:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jan 2020 09:32:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D0FDB180504 for ; Sun, 12 Jan 2020 23:39:17 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 12 Jan 2020 23:39:17 -0800 (PST) Received: by mail-ot1-f45.google.com with SMTP id b18so8122416otp.0 for ; Sun, 12 Jan 2020 23:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=w3pI3eJzppIUMG+6ofyRrAj6ej61kW90STSZaqzSoHE=; b=GAxU+0vrR2koU9iXAOH+lyL6avpLwDEv+nBzOp1j419T1Sp0mgpIHlOQjrDxJPj8rr j6IHx0MxSSJYpaWveP3WyRgu1kMdlF+pZzsdjFHFF4eNCnFAOXAsLOJz/GmJOxqCw3hO 4mq8c1cw5vEQfcnmylxFHenubdoIr22K9CK+/0T3bqpaA3zlAiglKSFzJtArEA3yBCtj pWJO8mChcvww0S/9EJAztTthS6OpehBMlRFwaz7/j0IozvR75LpRWE2TjkMj9I8X4tVQ kGq7hnbq34fY99g58YpgODvCS5A/bn/9lYSuqFhJI6btplDRnf0nZpuf4ldB/lm+889c ES3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=w3pI3eJzppIUMG+6ofyRrAj6ej61kW90STSZaqzSoHE=; b=maaigOKJ5x4msheSYpJT7l2PGeJf1kClfQmVaYh2USgHKI4/RtaeCL+rJwQWQ2C9Kq OpxSmP8Gi/vghUSiokkngeGMbag72AS9z0iGou9tE5+SJEIzUXw1Ae3d6bN42JVG5N8a XmKKs0YcJdEN3lJmaRuJQ1MIAA0epnXMQOnLBGQiCSpTsvmS62mmyNHrct0cFl9tgegF 68EsGDnK+2rAlYtxfZKToSlQwy0J8TxH9PLiKJjMiAd6fuRYYICKliJwXjUHeqot2S3g pJ+7F7r8rGLzjUylFU10Ces23oEpyhYp5cYVhSWAIBQ0h0myhQ3vQbtX5e+21KQZhFf/ +Thw== X-Gm-Message-State: APjAAAXXEHSJO94CHPOMKijZ3IjsWL43X2WdcW4zMjFgwwHwHr04O8j1 PXPAZABGZVn351mCSnmQp+0NxrqYeRPZpJF65xU= X-Google-Smtp-Source: APXvYqy76OVCtghKNXLtluOzb495GD3u7b0GkF7pdIly/Bs06rGKbq8T1jeHUDSpuhDy39rGZMlcmrvsxk5Dx9Qbw54= X-Received: by 2002:a05:6830:1042:: with SMTP id b2mr11913458otp.306.1578901156145; Sun, 12 Jan 2020 23:39:16 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 13 Jan 2020 07:39:05 +0000 Message-ID: To: Mike Schinkel Cc: Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Introducing compile time code execution to PHP preloading From: robehickman@gmail.com (Robert Hickman) I would say that my proposal is more about compile-time meta programming, and thus would not actually depend on preloading. It could also be ran during page requests and would be cached by opcache in the same way. However running it in that way could make the initial request before the opcodes are cached much slower. Hence why combining it with preloading would be advantageous. On Mon, 13 Jan 2020 at 00:45, Mike Schinkel wrote: > > > On Jan 12, 2020, at 1:57 PM, Larry Garfield wr= ote: > > > > Most notably, *not all code will be run in a preload context*. > > Can you give some concrete examples here? > > > Language features that only sometimes work scare me greatly. > > Do you have some examples of language features, from PHP or another lang= uage, that only work sometimes and that are known to be problematic. and wh= y they are problematic? > > > Doing one-time optimizations in preload that make the code faster, that= 's great. > > Though I think this proposal may need to be fine-tuned, I can envision ma= ny frameworks and CMSes written in PHP could improve both performance, rob= ustness and user-experience using preloading. > > One of the ways most useful would be to run code that ensures the framewo= rk/CMS APIs are being used correctly. If this code is included today in fr= ameworks and CMSes, it must run for every page load (on the web) when it co= uld be run once when OpCode is generated. This could potentially improve pe= rformance significantly, depending on how much checking it implemented. > > It could also improve performance of building data-driven structures at r= untime. I know that in the past I have had data driven structures that were= definitely very time-consuming on each page load. The WordPress admin doe= s tons of it. > > > Preload optimizations that make the code behave differently, that's ext= remely dangerous. > > Can you give some concrete examples where you fear this could happen? > > > "I changed one character and now I have to restart my webserver to see = if it did anything" is a bad place for PHP to be. > > As I envision it preloaded code of this nature would not be handled on se= rver reboot, but when the files have had their time stamps updated. If I am= not mistaken, PHP already does this (but I could be mistaken as I don't ha= ve expertise in PHP OpCodes.) > > Whatever the case I think this could easily be handled with a simple API = call to flush preloaded code which for debugging could be one of the first = things a developer would call in their codebase. > > > I am highly skeptical about allowing arbitrary preload/compile time beh= avior as it makes development harder and bifurcates the ecosystem. > > Given the copious performance and robustness benefits that preloading cou= ld provide, I would think we should try and identify specific concrete conc= erns rather than allow unidentified concerns from blocking a potentially gr= eat improvement to the language. > > So what specific concrete concerns can we identify? > > > To your specific examples, many are already possible today. Code gener= ation in a pre-execute build step is increasingly common; the Symfony ecosy= stem does a ton of it, I've implemented a compiled version of a PSR-14 Even= t Dispatcher, etc. > > Am I understanding correctly that requires a _build_ process, and not som= ething that a PHP developer can depend upon having available on any hosted = PHP server? > > > Code generation at that point is then impossible. Moving that code gen= to a preloader wouldn't help with that. > > As Robert stated, he is not proposing any code generation. > > His preloading concept would modify classes by manipulating the AST, whic= h, IMO would require an additional API. And I do think it is probably ortho= gonal to the idea of preloading code although I do think it would also have= great benefit too, but that preloading is probably a prerequisite. > > > I appreciate the intent here, but in practice I'd much rather we limit = preload optimization to things the engine can do for us, and reliably know = that it can do so without changing behavior. > > Limiting in that manner would effectively eliminate the possibility of se= rendipity that can occur when userland developers are empowered vs only tho= se who can sufficient agreement to add features to PHP. IOW, tiny subset of= problems could be solved if we limit vs. the number of problems developers= could solve for themselves and offer to the open-source to the community i= f userland developers are given more control over preloading. > > > For example, there's a ton of optimizations that can be done that rely = on working with pure functions only, but the engine today cannot know if a = function is pure. (Or I don't think it's able to figure it out for itself,= anyway.) I'd be fully in favor of ways that we could indicate to the engi= ne "this is safe to do more computer-science-y optimizations on, do your th= ing", and then implementing those optimizations in the engine rather than i= n user space. > > There are more innovations that can occur in computer science than just t= hose that depend on pure functions. Why must we limit ourselves to only con= sider problems that can be solved with pure functions? > > There are a lot of details we would need to work through to have a viable= proposal for userland preloading (vs. preloading a sysadmin can control), = but I assert we'd be better off optimisitically exploring the concept inste= ad of prematurely stifling exploration. > > -Mike