Reuse adapter sessions during execution

This commit is contained in:
2026-10-09 01:42:03 +00:00
parent a852301801
commit a7960e5e94
6 changed files with 328 additions and 32 deletions

View File

@@ -673,7 +673,7 @@ measures repeated parse plus help on the same fresh-per-session backend state.
## Stage 9: reuse the adapter session throughout root execution
**Status:** not started. **Prerequisite:** Stage 8.
**Status:** complete. **Prerequisite:** Stage 8.
**Files:** [execute.go](../../execute.go), [builtins.go](../../builtins.go),
private parser coordination, [execute_external_test.go](../../execute_external_test.go),
@@ -719,7 +719,63 @@ to confirm that signatures and backend isolation are unchanged.
**Completion:** every normal `Execute` path uses the selected OD-1 lifecycle and
all existing public handler and presentation semantics remain intact.
**Evidence:** pending.
**Evidence:** `GOWORK=off GOTOOLCHAIN=local GOPROXY=off GONOPROXY=none
GOSUMDB=off go test -mod=readonly -count=1 ./internal/cobra .` passed. Existing
help, parser, outcome, and cancellation coverage continues to pass. Added checks
for a successful flag-bearing invocation followed by local help with an empty
value, explicit false and omitted values, distinct contexts/streams across
executions, handler-returned usage after successful registration, and help plus
usage against metadata registered after a session was prepared. The built-in
help handler and top-level dispatcher share target resolution/rendering. Source
review confirms `Execute` prepares one session from the cached neutral tree;
presentation reuses it when the tree pointer is unchanged and prepares against
new metadata only after successful registration. Parsing, input factories,
checks, and handlers are not rerun for presentation. Public signatures and the
Cobra facade boundary are unchanged.
Measurements used Go 1.26.8, linux/amd64, Linux 6.17.0-41-generic, Intel Core
i5-7260U CPU @ 2.20 GHz, based on source revision `a852301` with this stage's
changes in the working tree. The five-sample command passed:
`GOWORK=off GOTOOLCHAIN=local GOPROXY=off GONOPROXY=none GOSUMDB=off go test -mod=readonly -run '^$' -bench '^BenchmarkPerformanceDispatch$' -benchmem -benchtime=200ms -count=5 .`.
Raw output is in `/tmp/commandkit-performance-dispatch-after-stage9.txt`;
focused wide and cold repeats are in
`/tmp/commandkit-performance-dispatch-stage9-repeat.txt` and
`/tmp/commandkit-performance-dispatch-stage9-cold-repeat.txt`.
Compared with the Stage 1 baseline, small repeated success measured
38,671–44,179 ns/op, 29,576–29,578 B/op, and 269 allocations (baseline:
31,066–41,041 ns/op, 33,209–33,210 B/op, 287 allocations). The timing ranges
overlap; bytes fell by about 3.6 KB and allocations by 18. Local help measured
85,120–91,091 ns/op, 41,428–41,430 B/op, and 509 allocations (baseline:
103,022–116,183 ns/op, 78,176–78,177 B/op, 810 allocations). Explicit help
measured 89,431–116,591 ns/op, 41,917–41,918 B/op, and 516 allocations
(baseline: 101,998–111,895 ns/op, 78,152–78,153 B/op, 815 allocations).
Parser usage measured 28,521–46,876 ns/op, 30,128–30,129 B/op, and 292
allocations (baseline: 62,596–74,475 ns/op, 66,363–66,364 B/op, 591
allocations). Handler usage measured 29,563–53,319 ns/op, 29,976–29,977
B/op, and 284 allocations (baseline: 61,878–72,264 ns/op, 66,211–66,212
B/op, 583 allocations).
The focused wide repeat measured success at 178,004–194,710 ns/op, 247,796–
247,806 B/op, and 1,758 allocations (baseline: 218,073–253,010 ns/op,
269,063–269,070 B/op, 1,898 allocations). Wide help measured 227,764–243,610
ns/op, 259,685–259,689 B/op, and 1,998 allocations (baseline: 491,172–
622,188 ns/op, 549,923–549,940 B/op, 4,033 allocations). Deep success
measured 151,780–172,540 ns/op, 124,410–124,412 B/op, and 881 allocations
(baseline: 119,958–139,625 ns/op, 139,787–139,791 B/op, 1,074 allocations),
so this run was slower while reducing bytes and allocations. Deep help measured
253,765–324,263 ns/op, 157,797–157,808 B/op, and 1,238 allocations; its
focused Stage 1 baseline was 300,155–326,094 ns/op, 294,882–294,896 B/op, and
2,408 allocations.
Cold small construction plus first execution measured 37,934–42,626 ns/op,
38,411–38,412 B/op, and 340 allocations (baseline: 38,152–50,235 ns/op,
38,275–38,276 B/op, 339 allocations). Cold wide measured 267,018–335,726
ns/op, 305,212–305,220 B/op, and 2,196 allocations (baseline: 251,945–
315,276 ns/op, 291,822–291,827 B/op, 2,184 allocations). Both timing ranges
overlap their baselines; retained session coordination adds a small cold
allocation/byte cost. Results show lower help/usage work and lower repeated
allocation costs, with timing variation on repeated success and deep dispatch.
## Stage 10: prepare configuration scope metadata once