Skip to content

perf(kernel): resolve configuration and cache path once per boot - #26

Merged
brianvarskonst merged 3 commits into
mainfrom
perf/memoize-kernel-configuration
Oct 23, 2026
Merged

brianvarskonst merged 3 commits into
mainfrom
perf/memoize-kernel-configuration

Conversation

@brianvarskonst

@brianvarskonst brianvarskonst commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Findings

Review findings K-P4 and K-P5 (one change, same code path):

  • KernelConfigurationResolver::packagePrefixes() read and parsed the root composer.json on every request unless KERNEL_PACKAGE_PREFIXES was set.
  • AbstractKernel::configuration() created a new resolver per call, so CachePath::resolve() (realpath walks, fileperms, is_file) ran for getCacheDir() and again inside KernelPackageManifestCache::cacheFile() on every request.

Change

  • AbstractKernel keeps one resolver per boot (reset on __clone() and shutdown()); the class is at the coding-standard property limit, so the single new property carries a justified phpcs:ignore.
  • The resolver memoizes the package prefixes and the resolved cache path for its lifetime (one boot). testCacheDirectoryReadsRealEnvironmentWithServerAndEnvPrecedence now uses a fresh resolver per precedence step; the other accessors still read the environment on each call.
  • BundleDiscovery and KernelPackageManifestCache accept an optional resolved cache directory (new trailing constructor parameter, default null keeps the previous behavior). The kernel passes its resolved path.

Verification

  • New KernelPackageManifestCacheTest::testExplicitCacheDirectorySkipsResolvingTheProjectCachePath.
  • Cache, discovery, bundle and lifecycle suites pass; composer cs and composer static-analysis pass in a PHP 8.5.12 container. The 7 PHPUnit notices are identical on main.

brianvarskonst and others added 3 commits October 23, 2026 23:47
AbstractKernel built a new KernelConfigurationResolver for every call, so the
cache path (realpath walks plus permission checks) was resolved two to three
times per request and the root composer.json was parsed for package prefixes on
every request. The kernel now keeps one resolver and one resolved cache path per
boot, the resolver memoizes the package prefixes, and bundle discovery receives
the resolved cache directory instead of resolving it again for the manifest.
@brianvarskonst
brianvarskonst merged commit 0cae3fb into main Oct 23, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the perf/memoize-kernel-configuration branch October 23, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant