Repository navigation
[PR] perf: deduplicate captured subagent sessions in linear time - #6668
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 — searched open+closed PRs/issues for Reviewed the diff, checked out the PR head in an isolated worktree, and ran targeted verification. This is a correct, minimal, well-tested perf fix. Verified live on the PR head (
Regression surface (existing behaviors of Diff: 3 files, +40/−4, every line on-purpose (the Set swap, the regression test, the benchmark). No unrelated / whitespace / lockfile churn. One note (not a blocker): the PR is 17 commits behind 八问(结构化审核结论)
判定:可合(mergeable)。 正确、最小、测试充分,无回归。合并前建议 rebase 到当前 master(无文件冲突,干净)。 |
Closes #6666
Problem
After an OpenCode fold, each newly captured child-session ID is checked with
Array.includesagainst all IDs already found. Capturing many distinct dispatches is therefore quadratic before the existing 100-ID sidecar limit applies, adding synchronous work to the compression path.Changes
Replace the growing-array membership checks with an insertion-ordered Set, then return its ordered IDs. The collector still returns every captured ID; the persistence limit remains where it was. No protocol, configuration, kernel or dependency changes.
Add a 5,000-session mixed-carrier regression covering duplicate IDs within and across call/result records, coverage filtering independent of Set input order, and the stored 100-ID prefix. A standalone benchmark exercises the real
syncSubagentSessionsproduction hook and validates both its persisted sidecar and the full capture result.Validation
applyRangesintegration that checks the real fold, receipt and byte-clean summary.npm run buildandgit diff --check: pass.Local benchmark
node --import tsx scripts/bench-subagent-capture.mjs 20000Node v24.22.1, Linux; 20,000 unique subagent sessions represented by 40,000 structured dispatch call/result messages. Three iterations per implementation, timing the production post-fold hook (including covered-set creation, extraction, deduplication and metadata update). Fixture construction is outside the timed interval; the expected 100 persisted IDs are checked after every iteration.
These local measurements describe this long-history hook only. Typical smaller histories have less work to remove, and overall model/compression latency is not measured by this benchmark.