perf(di:compile): memoize Interception Config scope reads during compilation#40614
perf(di:compile): memoize Interception Config scope reads during compilation#40614SamJUK wants to merge 1 commit intomagento:2.4-developfrom
Conversation
|
Hi @SamJUK. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
e47db2f to
43ea2dc
Compare
…ilation During setup:di:compile, Interception\Config\Config::generateIntercepted() is called twice per compile run — once per each of two separate pipeline phases. Each call invokes $this->_reader->read($scope) for every registered scope, parsing and merging di.xml files from scratch each time. The di.xml files do not change between the two calls within a single compile run. Add a $scopeReadCache keyed by scope name so the XML parse-and-merge happens only once per scope per process lifetime. Benchmark results: | Project | Interception cache before | Interception cache after | Saving | |-------------|--------------------------|--------------------------|--------| | sandbox | 4.8s | 1.8s | 63% | | ma-griggs | 8.7s | 2.1s | 76% | | elesi | 4.6s | 1.7s | 63% | Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
43ea2dc to
a7cb16c
Compare
|
@magento run all tests |
Description
Interception\Config\Config::generateIntercepted()is called twice during a singlesetup:di:compilerun:Operation\Interception)Operation\InterceptionCache)Both phases call
$this->_reader->read($scope)for each of the ~8 compilation scopes. Each call fully parses and merges alldi.xmlfiles for that scope. Thedi.xmlfiles don't change between the two calls within the same compile run, so the second set of reads is completely redundant.On a project with 607 di.xml files across 8 scopes, that's ~4,856 file reads and DOM parse operations being done twice, with nearly 5,000 of them wasted.
Fix: add a
$scopeReadCachearray property toConfig. On the first call for a given scope the result is stored; subsequent calls return the cached value. The cache is instance-scoped so it is automatically discarded between separatebin/magentoinvocations.This is safe because:
di.xmlfiles don't change during a compile runConfigobject is a DI singleton for the duration of the processRelated Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios
Timing comparison
To isolate the specific phase:
On a project with ~400 modules the Interception cache generation phase typically drops from ~1.8–4.6s to ~0.6–1.7s (63–76% reduction).
Output correctness
Benchmarks on real-world projects
Memory impact
Measured on a ~470-module install:
The ~29 MB increase is the cached scope data (8 scopes × ~3–4 MB each of parsed di.xml config) being retained across both phases instead of discarded and reloaded. For a CLI compile tool this is an acceptable trade-off and well within the typical
memory_limitused for compilation.Questions or comments
Happy to add integration-level coverage if needed. The existing unit test covers the cache behaviour directly.
Contribution checklist