perf(sdk): stop cloning turn streams in analyze hot paths#422
perf(sdk): stop cloning turn streams in analyze hot paths#422willwashburn wants to merge 1 commit into
Conversation
Aggregate per-session/per-file groups by `&TurnRecord` instead of cloning the full record. The biggest win is `overhead.rs`, which used to clone every applicable turn per file (~3x for Claude turns with two CLAUDE.md candidates plus AGENTS.md cross-checks). - `overhead`: per-file filter into `Vec<&TurnRecord>`; route through a new internal `attribute_claude_md_refs` so the public `attribute_claude_md` is a thin wrapper. - `hotspots`: `IndexMap<String, Vec<&TurnRecord>>` for the per-session groups; private `attribute_session` / `index_tool_results` now take `&[&TurnRecord]`. - `quality`: per-session groups borrow turns; private `infer_outcome_refs` / `compute_one_shot_rate_refs` drive the work and the public functions adapt via a single ref collect. - `compare`: hoist the model-name clone above the three `entry` calls so we allocate once per *new* model, not four times per turn. Closes #325.
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR eliminates ChangesTurnRecord reference-based aggregation optimization
🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Closes #325. Aggregate per-session / per-file groups in the analyze hot paths by
&TurnRecordinstead of cloning the full record.TurnRecordcarries aVec<ToolCall>plus optional file lists, so these clones are not cheap.overhead.rs: per-file filter now collectsVec<&TurnRecord>and routes through a new internalattribute_claude_md_refs. The publicattribute_claude_mdis unchanged — it adapts via a single ref collect. Biggest win: every Claude turn used to be cloned ~2× and every Codex/OpenCode turn ~1× across the default file candidates.hotspots.rs: the per-session group isIndexMap<String, Vec<&TurnRecord>>. Privateattribute_sessionandindex_tool_resultsnow take&[&TurnRecord].quality.rs: per-session aggregation borrows turns; privateinfer_outcome_refs/compute_one_shot_rate_refsdo the work. The publicinfer_outcomeandcompute_one_shot_ratekeep their existing signatures and adapt via a single ref collect.compare.rs: hoist the model-name clone above the threeentry/or_defaultcalls so we allocate one ownedStringper new model (instead of four per turn).by_model_categoryis now the canonical insertion gate sincemodel_setandmodel_totalsmay be pre-seeded by the model filter.The
describe_applies_tofollow-up the issue mentioned is already in main (usesSourceKind::wire_strreturning&'static str).Test plan
cargo build --workspacecargo test --workspace— all 657 SDK tests pass, plus CLI / sdk-node suitescargo clippy --workspace --all-targets— no new warnings from this change🤖 Generated with Claude Code
Generated by Claude Code