Repository navigation
perf(kernel): resolve configuration and cache path once per boot - #26
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Findings
Review findings K-P4 and K-P5 (one change, same code path):
KernelConfigurationResolver::packagePrefixes()read and parsed the rootcomposer.jsonon every request unlessKERNEL_PACKAGE_PREFIXESwas set.AbstractKernel::configuration()created a new resolver per call, soCachePath::resolve()(realpath walks,fileperms,is_file) ran forgetCacheDir()and again insideKernelPackageManifestCache::cacheFile()on every request.Change
AbstractKernelkeeps one resolver per boot (reset on__clone()andshutdown()); the class is at the coding-standard property limit, so the single new property carries a justifiedphpcs:ignore.testCacheDirectoryReadsRealEnvironmentWithServerAndEnvPrecedencenow uses a fresh resolver per precedence step; the other accessors still read the environment on each call.BundleDiscoveryandKernelPackageManifestCacheaccept an optional resolved cache directory (new trailing constructor parameter, defaultnullkeeps the previous behavior). The kernel passes its resolved path.Verification
KernelPackageManifestCacheTest::testExplicitCacheDirectorySkipsResolvingTheProjectCachePath.composer csandcomposer static-analysispass in a PHP 8.5.12 container. The 7 PHPUnit notices are identical onmain.