Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110694 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16752 invoked from network); 22 Jun 2020 11:27:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2020 11:27:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 331D4180509 for ; Mon, 22 Jun 2020 03:13:59 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 ; Mon, 22 Jun 2020 03:13:58 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id e22so2493644edq.8 for ; Mon, 22 Jun 2020 03:13:58 -0700 (PDT) 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; bh=hv0dgVVp8eKF3aOw5qtPs1YdYlPkoC0YRy1t8e1FSZc=; b=cw3jkHq11ZMToAJPqf3aA2JPzZz9YCmc42ocOIqJVbCos5MqthgjmnIsg8wJVqCuO9 ToNI4G+pLO1u3eoadWFs5pwtkgHXxYZXKYTQOOoP/qd8ECGZRaRRD5tKWm/kEjBw9MIH HWjwGsRu/+wZ7yokJNSBveUCzFhZY3oG53GKQJv4W56Cu4UwkHikgDPrtU73ojk9KdCr xaOSfokD+hP60coGLl0j629XksFnG0hFcdi9Zxh1xFyj2jzuSHTUCSmBAXoMcltxrTJv Np+qDJpqluqXQghkGLJ+udc8sZUe86g1qN7E+5pxuT+la5fv22eQRCqIyTm9kfn/JjEY LyHw== 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; bh=hv0dgVVp8eKF3aOw5qtPs1YdYlPkoC0YRy1t8e1FSZc=; b=MssPi3MNoex/V33jRN1SaXgTpmzQMpklNSxiiDfUpwxQ230+qrpUjY2Ok/RvXghljY 1MDVWBWBlbYcQBnRD5wxCF/Nb20nyIzUJh5GixxBKKfn3kVvtZHRH0rDxHmTepbGlP3M ggT2Zy2mt65mkzV4AcmNJGMiOaWgl9Us/4T7ydKltOlxjtrmOS45YMCAZZWCCmwkZJSC zWEnlBPKc4tnEElmxu45/oh7VQCO8SZw7RHB80dYsdQ8TZEyL6DYs3WYRR/uiPouKgMc InXFZm5YlmJzNw88bWKUMpDEC6AFMMjf4OAvtDX6PBAGUHzAldNFLPi9w7KI+KbI2DHZ twoA== X-Gm-Message-State: AOAM532aZK4XzGKehD3yL+t5LNuSck256o2YhiJ/PbBXoLezxxHBmxWk Az5BAs9maKi88QNcp7srQvjoaV58PfNo8EMitFbQH+O6ySc= X-Google-Smtp-Source: ABdhPJzZPmeM6tYuia5VWLBWkya0lMvQEVcECwmsL5H4dtVrE5melODfmtC0gh2uEFcyODz5GMIOfR3D+Oftzmf6VmE= X-Received: by 2002:aa7:c986:: with SMTP id c6mr16563481edt.335.1592820836527; Mon, 22 Jun 2020 03:13:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 22 Jun 2020 12:13:44 +0200 Message-ID: To: Nikita Popov Cc: PHP Internals List Content-Type: multipart/alternative; boundary="00000000000026f10b05a8a9804f" Subject: Re: [PHP-DEV] Resolve fallback-to-root-namespace in preloaded implementations From: nicolas.grekas@gmail.com (Nicolas Grekas) --00000000000026f10b05a8a9804f Content-Type: text/plain; charset="UTF-8" Hello Nikita, with preloading and Composer, we don't need anymore to consider autoloading >> for functions and/or constants. The reason is that basically Composer is >> already doing a great job at loading functions: just give it a list of >> files and it will ensure they are included all the time. Actually, >> Composer >> is just an example, all similar "require all the time" strategies work. >> >> The drawback of this approach used to be that requiring a bunch of >> (potentially unused) files could be costly. But now that we have >> preloading, this cost is zero. As such, autoloading functions/constants >> would serve no purpose. >> >> Then, we periodically have discussions about the rules for namespace >> resolution of functions/constants. The fallback-to-root-namespace has no >> measurable performance overhead - the cache is very effective. Yet, Nikita >> has stated a few times that knowing the type of the arguments of the >> function being called helps the engine a bit. With JIT, this might be >> (/become) more important (is that correct, Dmitry and/or Nikita?) >> >> I'm thus wondering: could we resolve the fallback-to-root-namespace rule >> at >> preload time, for all preloaded implementations? For runtime-loaded code, >> we would keep the current behavior. >> >> In practice, this means that during development (when preloading is not >> used), we would preserve all the hackability that the rule provides (PHP >> being a hackable engine is a big PRO, here, this can help e.g. testing a >> lot). The fallback-to-root-namespace is a wise pragmatic rule that serves >> the language well IMHO. But in prod, in full-perf mode (aka when >> preloading >> is enabled), this proposal would pave the way for better performance with >> JIT, if confirmed. >> >> WDYT? >> >> Nicolas >> >> PS: I fear I would be unable to implement anything related to this >> proposal >> so I'm just sharing the idea to see if it could be interesting. >> > > Hey Nicolas, > > I think this is something we should consider. Maybe not as default > behavior, but at least under an ini setting. Basically, any unqualified > call would get resolved to a global call or a namespaced call based on > which functions are declarated at preloading time. > An ini setting would work for me - I'd enable it all the time when using preloading. > I see one potential problem. If you have something like > > namespace Foo; > if (true) { > function strlen($x) {} > } > strlen("foo"); > > then depending on how the preloading is performed, PHP will not be aware > of the "Foo\strlen" function. Specifically if opcache_compile_file() > preloading is used, because it does not execute code. If "require" based > preloading is used, this is not a problem. > I see this as an inherent limitation to using opcache_compile_file(). Class aliases can lead to similar differences. Not something I would care about, especially if there is an ini setting to opt-in for the proposed behavior. I'm unfortunately entirely reliant on you or someone else that has the skills for implementing this... Thanks for your answer and your interest in the proposal! Nicolas --00000000000026f10b05a8a9804f--