Record algorithmic audit findings
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Automatic Usage Reporting Review
|
# Automatic Usage Reporting Review
|
||||||
|
|
||||||
Status: two open findings: documentation R1 and integration R2. Production code
|
Status: four open findings: documentation R1, integration R2, and efficiency
|
||||||
is unchanged by these reviews.
|
opportunities R3–R4. Production code is unchanged by these reviews.
|
||||||
|
|
||||||
## Scope and evidence
|
## Scope and evidence
|
||||||
|
|
||||||
@@ -162,3 +162,114 @@ feature with local shared-debug input, local and feature repeatable values,
|
|||||||
scoped/global flag aliases, an alias-only help prefix, operands after `--`,
|
scoped/global flag aliases, an alias-only help prefix, operands after `--`,
|
||||||
version, and completion. R2 was reproduced separately despite those passing
|
version, and completion. R2 was reproduced separately despite those passing
|
||||||
suites. No other new interaction defect requiring remediation was identified.
|
suites. No other new interaction defect requiring remediation was identified.
|
||||||
|
|
||||||
|
## R3: Partition occurrence preparation instead of rescanning argv for every feature
|
||||||
|
|
||||||
|
**Priority:** P3. **Status:** open. **Plan coverage:** Stages 2–4.
|
||||||
|
|
||||||
|
**Relevant code:** [execution.prepareFeatures](../../execute.go),
|
||||||
|
[typedInvocationFeature.prepare](../../invocation_feature.go), and
|
||||||
|
[prepareInputWithOccurrences](../../binding.go).
|
||||||
|
|
||||||
|
Each feature receives its own raw value/spelling slices, but receives the entire
|
||||||
|
`parsed.FlagOccurrences` log. Its call to `prepareInputWithOccurrences` rebuilds
|
||||||
|
the ordinal map by scanning that complete log. Captured ordered bindings can
|
||||||
|
also allocate and sweep an ordered array sized to the whole log, even when only
|
||||||
|
a few occurrences belong to the feature.
|
||||||
|
|
||||||
|
**Complexity:** let F be the installed feature count, N the parsed flag occurrence
|
||||||
|
count, and B the total feature binding count. Apart from metadata conversion and
|
||||||
|
caller-supplied converter work, successful feature preparation takes
|
||||||
|
Θ(F + B + FN) time and Θ(FN) cumulative
|
||||||
|
ordinal-index allocation. This is allocation churn, not a claim that all those
|
||||||
|
indexes remain live simultaneously. It can be quadratic when F and N grow
|
||||||
|
together. Even features with no flags scan every occurrence. A valid example is
|
||||||
|
F distinct flagless features plus N occurrences of one application repeatable
|
||||||
|
flag: each feature builds an index it never uses.
|
||||||
|
|
||||||
|
ckprompt currently contributes one feature, so this does not make the ordinary
|
||||||
|
single-feature path quadratic. The scaling problem concerns the new public
|
||||||
|
composition API as more features are installed.
|
||||||
|
|
||||||
|
**Refactoring opportunity:** build a binding-owner lookup and partition the
|
||||||
|
occurrence stream once, preserving canonical names, entered spellings, and
|
||||||
|
relative occurrence order within each input owner. Supply each feature and the
|
||||||
|
selected command with only their owned occurrences, using dense owner-relative
|
||||||
|
positions. Total indexing/preparation overhead can then be expected O(F + B + N),
|
||||||
|
plus the selected command's bindings and inherent conversion work. A shared
|
||||||
|
ordinal index is another possible approach, but it must also eliminate each
|
||||||
|
owner's full-N ordered-array allocation/sweep; sharing only the map leaves that
|
||||||
|
second source of repeated work intact.
|
||||||
|
|
||||||
|
This retains the selected typed binding machinery and directly implements Stage
|
||||||
|
2's intended partitioning by ownership. It does not reconsider parsing grammar,
|
||||||
|
feature order, conversion semantics, or the selected input/Run boundary. Preserve
|
||||||
|
alias spellings, malformed earlier occurrences, explicit false/empty values, and
|
||||||
|
`CaptureFlags` ordering in regression coverage with multiple features and local
|
||||||
|
bindings. No timing threshold or benchmark is necessary.
|
||||||
|
|
||||||
|
## R4: Share invocation-flag lookup across installation contexts
|
||||||
|
|
||||||
|
**Priority:** P3. **Status:** open. **Plan coverage:** Stages 1–2.
|
||||||
|
|
||||||
|
**Relevant code:** [validateInvocationFlagCollisions](../../registry.go),
|
||||||
|
[collectInvocationFeatures](../../registry.go), and the invocation-flag insertion
|
||||||
|
loop in [compileFlagAliases](../../flag_aliases.go).
|
||||||
|
|
||||||
|
There are two related command-by-flag products in installation:
|
||||||
|
|
||||||
|
- Collision validation builds a local spelling map for each command, then tests
|
||||||
|
every invocation flag against that map, including commands with no local flags.
|
||||||
|
- Alias compilation inserts the same invocation spellings into every canonical,
|
||||||
|
root, and alias-discovery context's map, regardless of whether aliases exist.
|
||||||
|
|
||||||
|
**Complexity:** let C be the command count, G the invocation flag count, L the
|
||||||
|
total local spelling count, and Q the number of alias-validation contexts
|
||||||
|
(canonical commands, root, and discovery prefixes). Collision checking takes
|
||||||
|
O(C + L + CG) expected time. The new alias insertion adds Θ(QG) expected time and
|
||||||
|
transient map entries. Together these introduce avoidable command/context-by-flag
|
||||||
|
work and storage. With C and G both proportional to n and no alias rules, Q is
|
||||||
|
C + 1 and this is quadratic despite linear-sized command/flag declarations.
|
||||||
|
|
||||||
|
**Refactoring opportunity:** construct one feature-only spelling index after the
|
||||||
|
existing reserved/duplicate checks. For collision validation, walk each command's
|
||||||
|
local spellings once and query that shared index, reducing that work to expected
|
||||||
|
O(G + C + L). For alias resolution, retain local canonical maps and provide a
|
||||||
|
lookup that also consults the shared invocation index. Both alias destination
|
||||||
|
resolution and source-collision checking should use that combined lookup. This
|
||||||
|
avoids copying G entries into all Q context maps, adding O(G + Q) storage instead
|
||||||
|
of Θ(QG). Merely fixing the collision loop leaves the alias-copying product, so
|
||||||
|
the two paths should be considered together.
|
||||||
|
|
||||||
|
These bounds describe the added invocation-flag work; they do not claim that the
|
||||||
|
entire installer becomes linear. Existing tree construction, selected sorting,
|
||||||
|
context/alias resolution, and validation of the prospective registry still have
|
||||||
|
their own costs. The shared lookup preserves atomic installation, validation in
|
||||||
|
both registration orders, canonical/scoped/global alias behavior, and ordinary
|
||||||
|
long/short spelling collisions. Regression checks should cover those semantics,
|
||||||
|
including inactive global aliases that become active when a feature is installed.
|
||||||
|
|
||||||
|
The plan selected deterministic traversal, handle deduplication, and validation
|
||||||
|
of every command; it did not select either nested loop or require duplicated
|
||||||
|
canonical maps. Indexing the global spellings once preserves those decisions.
|
||||||
|
|
||||||
|
## Algorithmic audit scope and evidence
|
||||||
|
|
||||||
|
Reviewed all eight stages against source baseline `b7467c5`, with prior findings
|
||||||
|
retained from `367d05b`:
|
||||||
|
|
||||||
|
| Stages | Algorithmic assessment |
|
||||||
|
| --- | --- |
|
||||||
|
| 1 | Preserved the explicitly selected traversal, root sorting, immutable capture and handle deduplication. R4 concerns unselected repeated spelling checks. |
|
||||||
|
| 2 | R3 concerns repeated full-log indexing; R4 concerns copied global spelling maps. Existing parser grammar and alias policies were not reconsidered. |
|
||||||
|
| 3–4 | Feature startup and report-producer traversal are linear in the feature count, apart from callback/report work. Existing lifecycle and public-assembly checks remain applicable. |
|
||||||
|
| 5 | Smoke projection visits each attempt once; added token/ratio adaptation is constant-size per attempt. Text rendering adds a linear pass for percentage comments. |
|
||||||
|
| 6 | Local summary adaptation reads a fixed set of native fields and uses `len(Members)`. Native group accounting and snapshot selection were expressly delegated upstream and were not reevaluated. |
|
||||||
|
| 7 | The maintained consumer's two-call pipeline is explicitly selected and bounded. No new domain algorithm was added. |
|
||||||
|
| 8 | Validation/documentation introduce no additional production algorithm. Prior R1 and R2 remain open. |
|
||||||
|
|
||||||
|
The findings follow from loop bounds and allocation sizes in the implementation;
|
||||||
|
no performance measurements or new benchmark/test code were added. Existing
|
||||||
|
focused `TestInvocationFeature*`, `TestInvocationFeatures*`, and
|
||||||
|
`TestRequiredInvocationFlag*` checks passed with Go 1.27.4. No additional ordinary
|
||||||
|
correctness defect was discovered in this algorithmic pass.
|
||||||
|
|||||||
Reference in New Issue
Block a user