Repository navigation
perf: skip tokenizing the default Config/Filters.php files during filter discovery - #10700
mdalikadar wants to merge 4 commits into
Conversation
neznaika0
left a comment
There was a problem hiding this comment.
See next lines:
// Don't include our main Filter config again...
if ($className === FiltersConfig::class || $className === BaseFiltersConfig::class) {
continue;
}This is almost done before you.
|
Thanks for the review. The check you quoted does already exist, but it runs after This PR moves the skip ahead of
I can add a comment next to the existing check making the ordering clearer if that would help. |
|
I suggest removing the class validation. It's the same thing. This will give you more speed |
|
Good point, thanks. Pushed. The class check is redundant once the two default files are skipped by path: APPPATH and SYSTEMPATH are realpath()'d, as are the results of search(), so the path match can't miss. I removed the check, so discovery now only skips the app and system configs by path and includes everything else. On my machine this saves about 16 µs per extra module |
neznaika0
left a comment
There was a problem hiding this comment.
Let’s take a look at the history #3459.
This detection was made so that users wouldn’t create their own classes in */Config/Filters.php (in modules). Instead of a class, you could use as global var:
<?php
$filters->aliases[] = ...;
$filters->required['before'] = ...;
$filters->globals = ...;
...There are no tests. I consider this 100% outdated and it should be removed. Creating a Registrar seems like the right way.
The funny thing is that checking for the presence of NS $className = $locator->getClassname($file); isn’t necessary if we insert a variable.
Sorry, I didn’t figure it out right away.
|
Thanks for the history link, that explains why the check exists. I already removed the class-name check in 4c1c369 (no discovered file is tokenized now), so I'm not sure which part is still open. Two questions:
Could you clarify what you mean by "if we insert a variable"? |
This code is a technical debt. Instead of using a class, it relies on a variable The second bug is that if we configure This PR can be reworked to close the task. |
|
Thanks, that makes sense: a discovered file that only edits I'm happy to rework this PR to remove @michalsn @lonnieezell, do you want that, or should I keep this PR as the small path-skip optimization? |
|
Sorry, but there's no point in optimizing deprecated methods. This particular one may be removed in |
|
Understood, thanks for the context. I'll close this, since there's no point optimizing a deprecated method. And thanks @neznaika0 for the history and the review. If you'd like discovery removed in 4.8 and want a hand with it (code, tests, changelog and upgrading note pointing module authors to a Registrar), let me know and I'll open a separate PR for that. |
Description
Filters::discoverFilters()ranFileLocator::getClassname()on everyConfig/Filters.phpit found, which reads and tokenizes the file, and then skipped the app and system ones because their class isConfig\FiltersorCodeIgniter\Config\Filters. In a default app those are the only two files, so every request parsed two files it never used.The two paths are now skipped by path, and the class-name check is removed, so no discovered file is tokenized anymore. The paths are built with
DIRECTORY_SEPARATOR, asAPPPATH,SYSTEMPATHand therealpath()results fromsearch()all use real paths.On my machine
new Filters()with discovery on goes from about 134 µs to about 60 µs (PHP 8.5 CLI, so indicative). Apps with extra moduleConfig/Filters.phpfiles save a further ~16 µs per file. It mostly helps apps withoutFileLocatorCached.Edge cases:
app/Config/Filters.phpthat declares a class other thanConfig\Filtersused to be included by discovery and is now skipped.Config\FiltersorCodeIgniter\Config\Filtersused to be skipped by the class check. It is now included, so it would fail as a redeclaration.Both break the framework's conventions, and discovery has been deprecated since 4.4.2.
Fixes #10616
Checklist: