On Mon, May 20, 2019 at 2:36 PM Gabriel O <gade...@gmail.com> wrote: > > Can you clarify? I'm not sure what performance improvement trick you > > are referring to, or what you mean by "importing all functions". Are > > you saying it's a misconception that triggering an autoloader on > > unqualified function calls in a namespace will slow down performance? > > As I understand it, this is the roadblock for function autoloading. > > Yes, this is misconception. Namespace resolutions are cached. First > fixer tool bringing support for this was correct: PHP-CS-Fixer auto > imports only optimized functions for this very same reason.
I'm confused, since this doesn't match what I've read elsewhere. For example, Nikita wrote the following last time function autoloading was discussed: [1] > Calling the autoloader if a global function with the name exists will > totally kill performance. This means that every call to strpos() or > any of the other functions in the PHP standard library will have to > go through the autoloader first, unless people use fully qualified > names (which, currently, they don't). This is completely out of the > question. In the same thread, it was suggested that a cache could be used to avoid repeatedly triggering the autoloader, but concerns were also pointed out with this: [2] > > Of course calling e.g. strpos() should not trigger the auto-loader > > repeatedly - can we cache the information that the auto-loader was > > attempted once during the current script execution? so that e.g. > > only the first call to strpos() triggers the auto-loader? > > I think triggering it even once for every internal function in the > code may be too much. > > > I suppose it would still happen once for every namespace from which > > strpos() gets called, so maybe this optimization doesn't help much. > > Exactly. Also, caching stuff assumes static environment. What if it > changes, e.g. autoloader gets different configuration? This is why I suggested the alternative of by default falling back to the global namespace for unqualified functions before triggering the autoloader, and allowing this fallback to be disabled for the rare case where functions in a namespace are spread across files and need to override a global function. I don't think this proposal changes anything related to function mocking. As you pointed out, libraries can already prevent mocking by importing or qualifying global function calls. Sincerely, Theodore [1]: https://externals.io/message/94895#94897 [2]: https://externals.io/message/94895#94956 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php