← Back to Pull requests

tree: match paths without allocating #999

Open
unknown opened this pull request with 359 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 19, 2026 09:35 UTC
Author

What this PR does, in one sentence

Makes tree.Path.Matches allocation-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 extends a service of another file allocate 1.7 GB, which is garbage-collector work and latency for every caller (docker compose commands, 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

Matches now 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 of strings.Split (empty path, trailing separator) behave the same.

Measured on synthetic but realistic files (services with about 15 attributes), Apple M1 Pro, 6 iterations, main against 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 Matches with the former split-based definition, and the absence of allocation by an AllocsPerRun test. The rest of the work on loading time (indexing the pattern tables, avoiding the reprocessing of the accumulated model at every include level, cloning less for extends.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

Diff: 359 lines (+269 / -90) across 4 files Reviewer: glours Review duration: 19930m
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
0.43
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
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
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: 42.6% (MEDIUM) · Higher = larger blast radius
42.6%
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: 22.7% · Safe to merge
22.7%