perf(cache): split runtime include map from transformation metadata - #594
Draft
lisachenko wants to merge 1 commit into
Draft
perf(cache): split runtime include map from transformation metadata#594lisachenko wants to merge 1 commit into
lisachenko wants to merge 1 commit into
Conversation
The autoloader materialized the full _transformation.cache array (filemtime plus cacheUri per file) on every request while only needing the original-path => cached-path mapping. The cache state is now written as two opcache-friendly files: - _include.cache: minimal originalPath => cacheUri|null map, read by AopComposerLoader on every request (roughly half the data); - _transformation.cache: full build metadata, now loaded lazily and only on the cache-miss/weaving paths (queryCacheState/flush) - a hot request never materializes it. A legacy cache directory without _include.cache keeps working: the map is derived from the metadata once and the next flush writes both files. New CachePathManager::queryIncludeMap() serves the runtime map. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1Z87HZ2iz23WPTtTYqFxE
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.
What
AopComposerLoadermaterialized the full_transformation.cachearray (filemtime + cacheUri per file) on every request, while the hot path only needs theoriginalPath => cachedPathmapping. The cache state is now two opcache-friendly PHP return-array files:_include.cache— minimaloriginalPath => cacheUri|nullmap (null = known but untransformed), read by the autoloader on every request via the newCachePathManager::queryIncludeMap(); roughly half the data of the old array._transformation.cache— full build metadata, unchanged format, now loaded lazily and only on the cache-miss/weaving paths (queryCacheState()/ flush). A hot request never materializes it.Details:
flushCacheState()loads the full metadata before merging (so unqueried entries are never dropped) and writes both files;setCacheState()keeps the in-memory include map coherent._include.cache, the map is derived from the metadata once at boot (same cost as before the split) and the next flush/warmup writes both files.findFile()semantics preserved exactly: production + known file → cached path (or original when untransformed, bypassing the filter); debug/unknown → filter path.Measured
Paired back-to-back runs (fixture project, ~30 cached files, warm cache, prod, PHP 8.5, median of 21): init 1.30 → 1.18 ms, full request −0.18 ms (−5 %). The fixture's cache map is small — the cost this removes scales linearly with project size (a 10k-file app materializes a 10k-entry × 2-field array per request today; after this PR it's a flat string map, and the metadata array not at all).
Tests
New
tests/Instrument/ClassLoading/CachePathManagerTestpins: both files written on flush, include map served without loading the full metadata (verified via the lazy-load flag), full metadata still lazily available, and the legacy-directory fallback. Full suite green on PHP 8.5/8.4 (2486 tests), PHPStan clean.Part of the boot-time series
Fifth and final PR of the series (container laziness → lazy aspects → lazy transformers → trusted prebuilt cache → cache-state split).
🤖 Generated with Claude Code
https://claude.ai/code/session_01V1Z87HZ2iz23WPTtTYqFxE
Generated by Claude Code