Record repeated glob prefix traversal cost
This commit is contained in:
@@ -158,6 +158,54 @@ is needed. Add a real-filesystem regression for both target forms that compares
|
||||
directory selection with the corresponding named/glob targets. Check bounded
|
||||
access as well, since it shares the normalization defect.
|
||||
|
||||
## 4. Avoid repeatedly resolving the ancestors of every literal glob prefix
|
||||
|
||||
Priority: P3. Status: open for consideration.
|
||||
|
||||
Relevant code: the loop in `globStartingCandidates`, lines 344–365 of
|
||||
[glob.go](../../internal/engine/glob.go); `explicitGlobCandidate` in that file;
|
||||
and `importEntryTarget` / `resolveImportLinkPath` in
|
||||
[filesystem_links.go](../../internal/engine/filesystem_links.go).
|
||||
|
||||
The new prefix owner inspects each literal component in order, as required by
|
||||
stage 7. However, each iteration calls `explicitGlobCandidate` with the entire
|
||||
accumulated access path. That calls `importEntryTarget`, which starts a fresh
|
||||
link-resolution walk from the namespace root. Its active/completed maps are
|
||||
local to that call and do not reuse the preceding prefix inspection.
|
||||
|
||||
Consider a link-free native filesystem exposing `fs.ReadLinkFS`, with all
|
||||
directories present and an absolute selector `/a1/a2/.../aD/*.yml`. At prefix
|
||||
depth i, `importEntryTarget` calls `resolveNativeImportPath`, whose frame
|
||||
evaluator issues an Lstat for each of the i components from the namespace root.
|
||||
The prefix loop therefore performs at least
|
||||
`1 + 2 + ... + D = D(D+1)/2` component Lstat calls, before counting its other
|
||||
inspection calls. This is Theta(D squared) explicit component inspections for
|
||||
a single chain, even with no links, aliases or wildcard branching. Host access
|
||||
also repeatedly resolves the accumulated parent/full path, and then separately
|
||||
canonicalizes it. Relative prefixes additionally revisit their base ancestors.
|
||||
|
||||
This bound counts ConfigKit-issued component inspections, not wall-clock time.
|
||||
Path-string processing and the filesystem implementation's own path-resolution
|
||||
costs are additional. The finding does not assert a particular measured cost or
|
||||
an end-to-end linear-time guarantee.
|
||||
|
||||
Potential refactoring: retain traversal-local resolved-prefix state, or extend
|
||||
the existing iterative evaluator to consume the literal prefix once while
|
||||
reporting each completed component for the existing directory, error and
|
||||
containment checks. On the link-free chain this can reduce explicit component
|
||||
inspections to O(D), plus any initial base resolution, rather than restarting
|
||||
for every prefix. Preserve separate lexical/physical coordinates and inspect a
|
||||
directory before consuming a following `..`; cleaning the complete prefix is
|
||||
not a substitute. Link expansions retain their own required work. Evaluate this
|
||||
alongside findings 1 and 3, reusing the selected evaluator rather than introducing
|
||||
a second resolver or persistent cache.
|
||||
|
||||
The plan expressly selects ordered component inspection and the iterative link
|
||||
algorithm, but does not require restarting that algorithm at every component.
|
||||
This opportunity concerns their call-site composition, not reconsideration of
|
||||
those decisions. It is an optimization candidate, not a new release gate or
|
||||
public performance promise.
|
||||
|
||||
## Initial implementation review coverage and validation
|
||||
|
||||
- Stage 1: ADR 0026 records the selected separation, and ADR 0022 changes only
|
||||
@@ -213,3 +261,32 @@ go test ./examples/consumers
|
||||
All passed. The earlier everyday-check and full-race results above remain
|
||||
applicable to unchanged production code. No production code or permanent tests
|
||||
were changed, and no publication or downstream dependency updates were made.
|
||||
|
||||
## Algorithmic audit coverage
|
||||
|
||||
Reviewed at `cda0fa5`, with production code still at `9d86e33`. All stages were
|
||||
considered in order. This follow-up adds finding 4; findings 1–3 remain open.
|
||||
|
||||
| Stage | Algorithmic assessment |
|
||||
| --- | --- |
|
||||
| 1 | Decision documentation introduces no runtime algorithm. |
|
||||
| 2 | The added context facts use fixed-size state and path validation; no growing input scan was introduced. |
|
||||
| 3 | Bounded/unbounded dispatch adds constant branching per operation and retains the existing read/accounting owners. |
|
||||
| 4 | The expressly selected iterative link frames and active/completed tracking are retained; ancestor restarts at their glob caller are covered by finding 4. |
|
||||
| 5 | Root parsing, segment decoding and literal normalization scan selector/path text; no new pairwise selector processing was found. |
|
||||
| 6 | Named/root unions use maps and deterministic sorting. Existing directory traversal, filtering and admission choices were preserved rather than reconsidered. Finding 3 remains the directory-identity correctness issue. |
|
||||
| 7 | Finding 4 identifies quadratic repeated prefix inspections; finding 1 remains the native parent-coordinate correctness gap. |
|
||||
| 8 | Candidate unions use composite-key maps and deterministic sorting. Distinct lexical/physical routes, wildcard ordering and visit budgets are deliberate choices; no additional defect was found in the new union code. |
|
||||
| 9 | Context construction makes one pass over sources, with path work per source and O(S) context records for S sources. Per-source passive roots do not trigger source reacquisition. |
|
||||
| 10 | Derived policy is a fixed-size context copy reused within the group; existing tier assembly and overlay algorithms remain unchanged. |
|
||||
| 11 | Capturing import policy adds a string field; compatibility checks perform path work without reacquiring the main document or its imports. Existing snapshot ownership remains intact. |
|
||||
| 12 | Lifecycle integration reuses existing composition, provenance and inspection algorithms; no alternate absolute-import pipeline was added. |
|
||||
| 13 | The consumer example adds no production algorithm. |
|
||||
| 14 | Documentation adds no runtime algorithm; finding 2 remains its contract correction. |
|
||||
| 15 | Validation adds no production algorithm or new performance gate. |
|
||||
|
||||
Evidence for finding 4 is the static call chain and loop bound above. No timing,
|
||||
allocation benchmarks, empirical performance measurements or new tests were
|
||||
needed. Existing successful semantic checks apply to unchanged runtime code;
|
||||
this pass changes only the audit record and validates its links and whitespace.
|
||||
No additional correctness findings were identified beyond those already recorded.
|
||||
|
||||
Reference in New Issue
Block a user