Skip to content

perf: skip tokenizing the default Config/Filters.php files during filter discovery - #10700

Open
mdalikadar wants to merge 2 commits into
codeigniter4:4.8from
mdalikadar:perf/filters-skip-default-discovery
Open

mdalikadar wants to merge 2 commits into
codeigniter4:4.8from
mdalikadar:perf/filters-skip-default-discovery

Conversation

@mdalikadar

Copy link
Copy Markdown
Contributor

Description
Filters::discoverFilters() ran FileLocator::getClassname() on every Config/Filters.php it found, which reads and tokenizes the file, and then skipped the app and system ones because their class is Config\Filters or CodeIgniter\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 before getClassname() is called. Every other file keeps the existing class-name check. The paths are built with DIRECTORY_SEPARATOR, as search() returns realpath() results.

On my machine new Filters() with discovery on goes from about 134 µs to about 60 µs (PHP 8.5 CLI, so indicative). It mostly helps apps without FileLocatorCached.

Edge case: an app/Config/Filters.php that declares a class other than Config\Filters used to be included by discovery and is now skipped. That breaks the framework's conventions, and discovery has been deprecated since 4.4.2.

Fixes #10616

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added 4.8 PRs that target the `4.8` branch. enhancement PRs that improve existing functionalities labels Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant