Repository navigation
perf(instrument): include known files natively in production - #755
Merged
Merged
Conversation
With Features::INTERCEPT_INCLUDES every include inside woven code went through FilterInjectorTransformer::rewrite(), which loaded the full _transformation.cache, stat-ed a cache path that does not exist for an untransformed file and fell back to php://filter: the file was filtered, checked for freshness and compiled again on every request (opcache never caches php://filter includes). _include.cache now also carries a 'files' map: every source known to the cache (path relative to the application root) => cached file (__DIR__ . '/...') or null when untransformed. In production rewrite() serves an include of a known source like the class map serves a known class: the original file when untransformed, the recorded cached file when woven, with no filter, no file_exists/freshness check and no load of the full metadata. Absolute paths with relative segments (__DIR__ . '/../x.php') are resolved before the lookup. Unknown files and debug mode still go through php://filter. CachePathManager::FORMAT_VERSION is bumped to 4 (an outdated PREBUILT_CACHE is rejected as before), the map follows a moved cache directory like the class map. Measured on a warm production request through php -S with opcache (JIT off), 20 includes of 150-line untransformed files + 1 woven file, base/head interleaved, 25 rounds x2, medians: - 20 untransformed includes: 5021-5286 us -> 210-224 us (~255 -> ~11 us per include) - woven include (which includes one more file): 231-243 us -> 6 us - whole request: 5874-5927 us -> 652-653 us - _transformation.cache loaded on a warm request: 25/25 -> 0/25 Transformation performance group (8 interleaved runs, alternating order): all head ratios within noise (-1.7%, +7.6%, +0.5%). Closes #746 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #755 +/- ##
============================================
+ Coverage 97.61% 97.79% +0.17%
- Complexity 1830 1841 +11
============================================
Files 104 104
Lines 4831 4849 +18
============================================
+ Hits 4716 4742 +26
+ Misses 115 107 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… include On Windows the cached file recorded for a woven include keeps the native separators of the woven source path, so the functional test builds the expected path with DIRECTORY_SEPARATOR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
lisachenko
marked this pull request as ready for review
October 7, 2026 23:01
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 and why
Fixes #746.
The problem
Features::INTERCEPT_INCLUDES, everyinclude/requirein woven code goes throughFilterInjectorTransformer::rewrite(). In production, a file with no woven copy (templates, config files, plain PHP) took this path:_transformation.cachewas loaded.file_exists()was called on a cache path that doesn't exist.php://filter. It was read by the stream filter, checked for freshness, and compiled on every request, because opcache never cachesphp://filterincludes.The change
_include.cachegets afilessection. It maps every source known to the cache (path relative toappDir) to its cached file (__DIR__ . '/…'), or tonullwhen the source was not transformed.CachePathManager::FORMAT_VERSIONgoes from 3 to 4.flushCacheState(), kept up to date within a request bysetCacheState(), and emptied byclearCacheState().CachePathManager::findIncludeFile()answers from this map only; it never loads the full metadata.rewrite()in production:file_exists();php://filter, as before./.are resolved first, so the common__DIR__ . '/../file.php'finds its record.PREBUILT_CACHEis still rejected with the hint to runcache:warmup:aop.__DIR__-based.UPGRADE-4.0.md, andsrc/Instrument/AGENTS.mdare updated.Numbers
INTERCEPT_INCLUDESin production mode. One woven class does 20requires of 150-line untransformed templates, plus one include of a woven file that includes another file.php -Swith opcache on and JIT off. Basec3fcd30and head requests interleaved, 25 rounds, run twice; medians, measured in-request withhrtime._transformation.cacheloaded on a warm requestThe ~11 µs per include on head still includes the one-time setup on the first
rewrite()call (the stream filter is still registered there).Transformation performance group (base vs head, 8 runs alternating the order, change in the head/base ratio): default rules −1.7%, all rules +7.6%, WeavingTransformer +0.5%.
rewriteNode()is unchanged.Behaviour notes
_include.cache: it grows by one entry per known source. opcache keeps the constant array as is; a CLI run without opcache parses a slightly bigger file.Tests
FilterInjectorTransformerTest: untransformed file (relative path resolved), path with/../, woven file (never stat-ed), unknown file goes through the filter, and debug never consults the map.CachePathManagerTest: the map is written and read back without the full metadata. Also covered:nullentries, files outsideappDir, unknown files, updates within a request, clear, and a moved cache.tests/Functional/IncludeInterceptionTest.php:FileIncluder, woven only byINTERCEPT_INCLUDES; a plain and a woven include file;bin/includes.php;production_includesandmoved_includes_cache, the second a prebuilt cache in a moved directory;_transformation.cacheis not loaded;Checklist
type(scope): summary)composer checkpasses (phpunit: 3000 tests, phpstan level 10, php-cs-fixer, run locally)🤖 Generated with Claude Code
https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Generated by Claude Code