Skip to content

perf(cache): make PREBUILT_CACHE a real trusted-cache mode - #593

Merged
lisachenko merged 1 commit into
masterfrom
claude/goaop-i5-prebuilt-cache-mode
Aug 26, 2026
Merged

perf(cache): make PREBUILT_CACHE a real trusted-cache mode#593
lisachenko merged 1 commit into
masterfrom
claude/goaop-i5-prebuilt-cache-mode

Conversation

@lisachenko

Copy link
Copy Markdown
Member

What

Features::PREBUILT_CACHE documents "do not check the cache presence and assume that cache is already prepared", but its only effect was skipping a single is_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 source filemtime comparison, no hasAnyResourceChangedSince() tracked-resource check.
  • CachedAspectLoader: an existing advisor cache file is trusted without the file_exists + double-filemtime freshness 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_CACHE constant 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/filemtime syscalls 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/CachedAspectLoaderTest pins 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

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
@lisachenko
lisachenko marked this pull request as ready for review August 26, 2026 09:34
@lisachenko
lisachenko merged commit 93a42fa into master Aug 26, 2026
7 checks passed
@lisachenko
lisachenko deleted the claude/goaop-i5-prebuilt-cache-mode branch August 26, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants