Record scoped enumeration efficiency finding
This commit is contained in:
@@ -5,8 +5,9 @@ Scope: the nine stages of [implementation.md](implementation.md), the settled
|
||||
[result-value roadmap](result-value.md), and accepted
|
||||
[ADR 0024](../adr/0024-compare-inspection-views-across-application-types.md).
|
||||
|
||||
No implementation changes were made during this review. Both findings below
|
||||
remain open.
|
||||
No implementation changes were made during these reviews. Findings 1–2 come
|
||||
from the correctness/architecture review; finding 3 comes from the subsequent
|
||||
algorithmic review. All findings below remain open.
|
||||
|
||||
## 1. Terminal availability still depends on recursive schema validity
|
||||
|
||||
@@ -97,7 +98,48 @@ ordinary Go typed-nil behavior explicit where needed; do not promise deep copies
|
||||
frozen execution settings or concurrent mutation safety. Align the wording with
|
||||
finding 1's corrected implementation, without redefining the intended contract.
|
||||
|
||||
## Stage-by-stage disposition
|
||||
## 3. Scoped path enumeration unnecessarily copies all effective metadata
|
||||
|
||||
**Priority:** P3. **Status:** Open. **Plan stage:** 3 (also exercised in stage 6).
|
||||
|
||||
**Relevant code:** `InspectionView.HistoricalPaths` in
|
||||
[inspection_view.go](../../internal/engine/inspection_view.go), line 62;
|
||||
`Inspection.Metadata` in [load.go](../../internal/engine/load.go);
|
||||
`cloneMetadata` in [load_metadata.go](../../internal/engine/load_metadata.go);
|
||||
and the existing enumeration in
|
||||
[history_select.go](../../internal/engine/history_select.go).
|
||||
|
||||
The new enumeration calls `v.inspection.Metadata().HistoricalPaths()`. Metadata
|
||||
first clones every effective path and FieldInfo, including origin locations,
|
||||
inheritance steps and contributor records. HistoricalPaths then reads only the
|
||||
shared frozen history model; none of those copied effective records are used.
|
||||
The view discards that complete metadata copy after filtering the returned paths.
|
||||
|
||||
**Complexity:** let P be the number of distinct historical pointers, B their
|
||||
aggregate token/string size, and C the total effective-metadata copy work and
|
||||
storage (effective paths, field records and nested origin data). In addition to
|
||||
the deliberately reused historical enumeration's O(P log P) string comparisons,
|
||||
O(B) parsing and scope-filtering work, each call incurs O(C) unnecessary time
|
||||
and temporary storage. String comparison costs additionally depend on pointer
|
||||
lengths. K view enumerations repeat that unused copying K times. With flat,
|
||||
short paths and small origins, sorting may still dominate; this is an avoidable
|
||||
additive metadata/provenance cost, not a claim that all enumeration is quadratic.
|
||||
|
||||
**Remediation:** enumerate through the retained private metadata directly, for
|
||||
example `v.inspection.metadata.HistoricalPaths()`, then retain the same scope
|
||||
filter. That existing method already constructs fresh detached Paths from the
|
||||
frozen history inventory. It therefore does not need a preceding clone of the
|
||||
unrelated effective fields. This removes O(C) work/storage without changing the
|
||||
selected enumeration/sorting algorithm, adding a cache or inventory, or exposing
|
||||
private records. Keep the public view's Metadata() and the original result's
|
||||
Metadata() ownership behavior unchanged. This local bypass does not require the
|
||||
broader deferred metadata-handoff redesign in future.md.
|
||||
|
||||
Existing scoped enumeration, numeric-shape history, root/absent/zero-view and
|
||||
metadata-detachment tests are appropriate regression coverage. Do not add timing,
|
||||
allocation-threshold or private-call-count tests merely for this simplification.
|
||||
|
||||
## Correctness review: stage-by-stage disposition
|
||||
|
||||
| Stage | Review result |
|
||||
| --- | --- |
|
||||
@@ -123,6 +165,39 @@ Using the locally installed Go 1.27.4 toolchain with `GOTOOLCHAIN=local`,
|
||||
- Local Markdown file targets and heading anchors were checked across the changed
|
||||
documentation; all 441 checked local links resolved.
|
||||
|
||||
No other required correctness, architecture, or strengthened-contract finding was
|
||||
identified. This review does not claim real downstream adoption, concurrent
|
||||
mutation support, narrower subtree diff cost, or a release/publication check.
|
||||
The original correctness review identified no other required correctness,
|
||||
architecture, or strengthened-contract finding. These reviews do not claim real
|
||||
downstream adoption, concurrent mutation support, narrower subtree diff cost, or
|
||||
a release/publication check.
|
||||
|
||||
## Algorithmic review: scope and conclusions
|
||||
|
||||
Reviewed the same implementation (`7a9ce01`, unchanged at audit checkout
|
||||
`a57afc7`) stage by stage, without benchmarks or production changes:
|
||||
|
||||
- Stages 1–2: map and field selection use direct lookups; sequences use checked
|
||||
indexing; pointer-loop detection and descriptor caching are operation-local.
|
||||
Full descriptor reuse and its schema-construction costs were selected in the
|
||||
plan. Finding 1 remains the separately recorded correctness issue.
|
||||
- Stage 3: canonical scope construction and segment-aware containment are
|
||||
straightforward; finding 3 removes an unselected, unused metadata clone from
|
||||
enumeration. Unfiltered detached Metadata remains part of the chosen API.
|
||||
- Stage 4: frozen-tree lookup uses the existing mapping index, followed by the
|
||||
selected snapshot redaction and rendering machinery. No new finding.
|
||||
- Stage 5: whole-result diff followed by scope filtering was explicitly chosen.
|
||||
Its comparison/redaction/sorting costs were not reconsidered; filtering is a
|
||||
single pass over differences with segment-aware containment. No new finding.
|
||||
- Stage 6: history, source-context and explanation queries delegate to their
|
||||
existing owners; the enumeration issue is covered by finding 3. Deferred
|
||||
narrower explanation replay and shared schema caches remain outside scope.
|
||||
- Stages 7–8: example registration composition and owned resource/settings copies
|
||||
use ordinary linear operations in the data copied. No nested repeated search
|
||||
or new algorithmic correctness issue was identified.
|
||||
- Stage 9: documentation introduces no runtime algorithm. Finding 2 remains open.
|
||||
|
||||
Validation used Go 1.27.4 with local/offline settings. Focused public
|
||||
`TestResultValue|TestInspectionView`, engine
|
||||
`TestResultValue|TestMetadataHistoricalPaths|TestHistorySelection`, and consumer
|
||||
`TestComponentHandoff|TestComposedConsumersShareOneLoad` tests passed with
|
||||
`-count=1`. The cost analysis follows the actual call chain and loops; no empirical
|
||||
performance claim or new performance guarantee is made.
|
||||
|
||||
Reference in New Issue
Block a user