tree: match paths without allocating #999
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 359 lines diff across 4 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
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #999"
general
weight: 0.35
glours
What this PR does, in one sentence
Makes
tree.Path.Matchesallocation-free, which cuts the time to load a large Compose file by a factor of 2.5 to 3.5 and the memory it allocates by a factor of 6 to 11, with no change of behavior.Context
Loading a Compose file is cheap in peak memory (20 to 70 MB of RSS on the files below) but allocates a lot: 200 services allocate 311 MB, and 400 services that
extendsa service of another file allocate 1.7 GB, which is garbage-collector work and latency for every caller (docker composecommands, language servers, tools embedding the library).Profiling points at one function. Canonicalization, defaults, validation, path resolution, merge, unicity, interpolation and omit-empty all walk the document and, for every node, test the node path against every pattern of a table (20 to 70 entries) with
Path.Matches. Each call split both paths into slices, only to compare them segment by segment and throw them away. That accounts for 82 to 91% of the bytes allocated on the files measured.What the PR brings
Matchesnow walks the path and the pattern segment by segment, without building anything, and stops at the first segment that differs. Same semantics: same depth required,*matches any segment, and the edge cases ofstrings.Split(empty path, trailing separator) behave the same.Measured on synthetic but realistic files (services with about 15 attributes), Apple M1 Pro, 6 iterations,
mainagainst this branch:| Scenario | Time | Allocated |
|---|---|---|
| 200 plain services | 355 → 138 ms | 311 → 53 MB |
| 200 services extending a service of another file | 657 → 336 ms | 655 → 273 MB |
| 200 services in chains of 5
extends| 294 → 115 ms | 252 → 47 MB || 20
includes sharing a common file | 1087 → 380 ms | 927 → 110 MB || 16 nested
includes (160 services) | 1517 → 498 ms | 1316 → 119 MB || 50 services, 8 override files | 399 → 156 ms | 326 → 51 MB |
The equivalence with the previous behavior is locked by a table of edge cases and a fuzz target comparing
Matcheswith the former split-based definition, and the absence of allocation by anAllocsPerRuntest. The rest of the work on loading time (indexing the pattern tables, avoiding the reprocessing of the accumulated model at everyincludelevel, cloning less forextends.file) is left to follow-ups; this one is the smallest change that brings most of the gain.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, and the gain is beyond that factor: 2.5 to 3.5 times faster and 6 to 11 times less memory allocated.
🤖 Generated with Claude Code