loader: copy only the extended chain of an extends.file base #1000
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 297 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.341
Real PR Conversation Timeline
1 comments
"Review active on #1000"
general
weight: 0.35
glours
What this PR does, in one sentence
Makes the memory cost of
extends.filelinear in the number of extending services, by handing each of them a copy of the service chain it extends instead of a copy of the whole extended file.Context
The extended file is loaded once and cached, but every service extending it received a deep copy of all its services, because resolving an
extendschain writes merged entries back into the map it is given. With n services extending a file of n services, that is n² services copied: the memory allocated per service grows with the size of the project, and shared base files, a common way to factor a stack, get more expensive the more they are used.What the PR brings
Each extending service gets a deep copy of the service it extends and of the services that one extends in the same file, which are the only entries the chain reads and writes. A service extending a file of its own leaves the copy and the chain goes on in a copy of that file. The cache keeps the loaded services as they are, as nobody gets that map anymore. Results, errors (missing service, circular reference) and the isolation between extending services are unchanged: the new behavior tests also pass on the previous code.
Measured with
BenchmarkExtendsFile(n services extending n services of another file, Apple M1 Pro, 6 iterations), the memory allocated per service no longer grows with n:| n |
main| this PR ||---|---|---|
| 50 | 68 ms, 57 MB (1.14 MB/service) | 68 ms, 51 MB (1.02 MB/service) |
| 100 | 137 ms, 125 MB (1.25 MB/service) | 127 ms, 102 MB (1.02 MB/service) |
| 200 | 312 ms, 296 MB (1.48 MB/service) | 288 ms, 203 MB (1.02 MB/service) |
At these sizes the gain in time is modest, the rest of the loading dominating it; what changes is the growth: the cost of the copies is now proportional to the number of extending services instead of to its product with the size of the extended file.
This follows the erooM law promoted by Tristan Nitot (_Effort Radicalement Organisé d'Optimisation en Masse_: optimize software by a factor of two every two years, by finding the components that consume the most resources and optimizing them). Profiling found the component here: the memory allocated per extending service no longer grows with the size of the project.
🤖 Generated with Claude Code