Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108107 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11796 invoked from network); 13 Jan 2020 02:39:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jan 2020 02:39:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC29F1804F2 for ; Sun, 12 Jan 2020 16:45:47 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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-yw1-f44.google.com (mail-yw1-f44.google.com [209.85.161.44]) (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 16:45:47 -0800 (PST) Received: by mail-yw1-f44.google.com with SMTP id z7so4884227ywd.4 for ; Sun, 12 Jan 2020 16:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=P7xC8U/H+Hyw9iqgVgDS0TobYT46VWJ3PAVxLjxk8ek=; b=J7+zoMh3Cv73cZC/qUSJqYFFxtDyBHbhumL/iR58lT0l9lQjnxOXd02mCkQbIZN7+5 GgYfZWrJ2wZnstxXXxJufpMJbxnX0FAb3EPo1oqHCtFas2lbZX82VPI0m5obQTKjjWrn V2Ipmi4MyVmT4yP8piqnKd2mvgoWxfhClO9gxZz5MxZ+jC+KiGw6qE4yhfsKv72Cq0a2 XDZYqyPIj96lEgrXuLowesqEIfxhGQz2g5aqh50z5ynCTl0g+uknvUG8tuvuoAnnByV6 qoSmkwEErTLslbs+oDDcVxdcAR5ccfKbWj1JCGZ9p+F8GLjhF09xZ93IVCC0PUp47YQC YR1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=P7xC8U/H+Hyw9iqgVgDS0TobYT46VWJ3PAVxLjxk8ek=; b=rzUfajtf0I3yoZta92VTSdVz+YJlwcQ2vQC9sTITLXxxwA0xb7YHx5oGUsYAqpBHMW TsV9/DP1VY8nmxZNDyA1bWopLoTy078RE8fJ8zdVDJK1rZl7QwpO/hVQQ4hsCsFt8UBK 7TLOh5nUIj6xZf2Oi5Bbr0IsS5+aoOBGuElpUJO/Z5SzSYWqnp4JINNpD45TNHrsR9By hqdu6wXcQOzSmI5gpfnRtO/wklwf5PzpX2G5dz2B1B+Al5yDapD0oSoQ5SEK33hYDfOI fWBdrEX3cxYjh6BBy/E6lkGNHOiu6X5ri83vVP4AhbLVQs4kisrI+YLaI4iD1VZQ1QUE ycEA== X-Gm-Message-State: APjAAAUn56gUVie3r0Q8nJ6VRQbPFqXTQYdsAwSzPMAJT0cIARf3Kkdc mI0fMR0U0ERn8C2Xbk888fzJNA== X-Google-Smtp-Source: APXvYqxI69BVbdTVoYl5YD1f8XruS70Qc05eGVqxGBvm448S201V6DL4KO06G1jd/VfHchOyXGhr/A== X-Received: by 2002:a25:5544:: with SMTP id j65mr7315217ybb.283.1578876341220; Sun, 12 Jan 2020 16:45:41 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:6144:8f7e:ef77:8424? ([2601:c0:c680:5cc0:6144:8f7e:ef77:8424]) by smtp.gmail.com with ESMTPSA id c66sm4536120ywf.96.2020.01.12.16.45.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jan 2020 16:45:40 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_914960AE-6E0A-475C-A61E-79FA8B007142" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Sun, 12 Jan 2020 19:45:39 -0500 In-Reply-To: Cc: php internals To: Larry Garfield References: X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Introducing compile time code execution to PHP preloading From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_914960AE-6E0A-475C-A61E-79FA8B007142 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Jan 12, 2020, at 1:57 PM, Larry Garfield = wrote: >=20 > Most notably, *not all code will be run in a preload context*. =20 Can you give some concrete examples here? > Language features that only sometimes work scare me greatly. =20 Do you have some examples of language features, from PHP or another = language, that only work sometimes and that are known to be problematic. = and why they are problematic? > Doing one-time optimizations in preload that make the code faster, = that's great. =20 Though I think this proposal may need to be fine-tuned, I can envision = many frameworks and CMSes written in PHP could improve both performance, = robustness and user-experience using preloading. =20 One of the ways most useful would be to run code that ensures the = framework/CMS APIs are being used correctly. If this code is included = today in frameworks and CMSes, it must run for every page load (on the = web) when it could be run once when OpCode is generated. This could = potentially improve performance significantly, depending on how much = checking it implemented. =20 It could also improve performance of building data-driven structures at = runtime. 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 does tons of it. > Preload optimizations that make the code behave differently, that's = extremely 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 = server 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 have expertise in PHP OpCodes.)=20 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 = behavior as it makes development harder and bifurcates the ecosystem. Given the copious performance and robustness benefits that preloading = could provide, I would think we should try and identify specific = concrete concerns rather than allow unidentified concerns from blocking = a potentially great improvement to the language. So what specific concrete concerns can we identify? > To your specific examples, many are already possible today. Code = generation in a pre-execute build step is increasingly common; the = Symfony ecosystem does a ton of it, I've implemented a compiled version = of a PSR-14 Event Dispatcher, etc. Am I understanding correctly that requires a _build_ process, and not = something 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. =20 His preloading concept would modify classes by manipulating the AST, = which, IMO would require an additional API. And I do think it is = probably orthogonal 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. =20 Limiting in that manner would effectively eliminate the possibility of = serendipity that can occur when userland developers are empowered vs = only those 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 if 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 engine "this is safe to do more computer-science-y optimizations = on, do your thing", and then implementing those optimizations in the = engine rather than in user space. There are more innovations that can occur in computer science than just = those that depend on pure functions. Why must we limit ourselves to only = consider 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 instead of prematurely stifling exploration. -Mike= --Apple-Mail=_914960AE-6E0A-475C-A61E-79FA8B007142--