← Back to Pull requests

loader: copy only the extended chain of an extends.file base #1000

Open
unknown opened this pull request with 297 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 19, 2026 09:51 UTC
Author

What this PR does, in one sentence

Makes the memory cost of extends.file linear 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 extends chain 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

Diff: 297 lines (+222 / -75) across 3 files Reviewer: glours Review duration: 19915m
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
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40% (MEDIUM) · Higher = larger blast radius
40%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 21.3% · Safe to merge
21.3%