perf(cache): make PREBUILT_CACHE a real trusted-cache mode - #593
Merged
Conversation
Previously Features::PREBUILT_CACHE only skipped a single is_writable() check while every other freshness/stat check still ran, contradicting its documented purpose. With the feature enabled: - CachePathManager skips the cache-directory existence/writability probes entirely (the cache is built at deploy time; also covers read-only file systems). - CachingTransformer trusts an existing cache record as-is: no source filemtime comparison, no tracked-resource freshness check. - CachedAspectLoader trusts an existing advisor cache file without the file_exists/filemtime freshness pair; a corrupt file falls back to the direct loader WITHOUT rewriting, keeping read-only file systems safe. Staleness under the flag is the deployer's responsibility (rebuild the cache on deployment); without the flag all freshness rules are unchanged. 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
Features::PREBUILT_CACHEdocuments "do not check the cache presence and assume that cache is already prepared", but its only effect was skipping a singleis_writable()check — every other stat/freshness check still ran. With this PR the flag means what it says:CachePathManager: skips the cache-directory existence/writability probes entirely (is_dir/mkdir/is_writable) — the cache is built at deploy time; also covers read-only file systems (GAE, phar).CachingTransformer: an existing cache record is trusted as-is — no sourcefilemtimecomparison, nohasAnyResourceChangedSince()tracked-resource check.CachedAspectLoader: an existing advisor cache file is trusted without thefile_exists+ double-filemtimefreshness pair; a corrupt/empty file falls back to the direct loader without rewriting, keeping read-only file systems safe.Without the flag, all freshness rules are unchanged. Semantics documented on the
Features::PREBUILT_CACHEconstant and in the CHANGELOG: build the cache at deploy time (bin/aspect cache:warmup:aop); staleness under the flag is the deployer's responsibility.Measured
On the small fixture project the wall-time delta is within run-to-run noise: the flag eliminates a handful of stat/
filemtimesyscalls per request (µs-scale on a local SSD). The practical wins are on slow/networked/read-only filesystems where each stat is expensive, and semantic: the flag now actually delivers its documented contract, which the deployment docs can rely on.Tests
New
tests/Core/CachedAspectLoaderTestpins the three behaviors: a deliberately stale advisor cache is trusted under the flag, the same stale cache is rebuilt through the direct loader without the flag, and a corrupt cache file falls back without being rewritten. Full suite green on PHP 8.5/8.4 (2484 tests), PHPStan clean.Part of the boot-time series
Fourth of five sequential PRs (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