Skip to content

perf(agent): reduce tool-result availability allocations - #2028

Merged
JAORMX merged 1 commit into
mainfrom
fix/tool-result-allocations
Oct 1, 2026
Merged

JAORMX merged 1 commit into
mainfrom
fix/tool-result-allocations

Conversation

@JAORMX

@JAORMX JAORMX commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Routine, performance-only repair for the allocation regression following #2013. No public API, event-ordering, guardrail, cancellation, persistence, or model-history contract changes.

  • Keep the first eight published call IDs in the existing run-local publisher; allocate the overflow map only for longer runs. Preserve the original mutex scope and lifetime-long duplicate suppression.
  • Store each read's availability bit in its existing batch record instead of allocating a parallel boolean slice.
  • Capture Go 1.27's per-iteration worker index directly, avoiding the extra goroutine argument wrapper.
  • Cover inline/overflow boundaries, empty IDs, canonical-first and availability-first publication, cancellation replacements, fresh-run isolation, and exact stream/sink sequencing.

No CI jobs, thresholds, baselines, caches, pools, or dependencies were added or changed. slices.Contains is from the standard library.

Allocation evidence

Profile and escape analysis identified the per-run publication map, boolean slice, and worker argument wrappers. Five local samples agreed for every benchmark below (-cpu=4 -benchmem -count=5).

Benchmark Before After Allocations removed
RunReadOnlyTurn 170 166 4
RunReadParallelTurn 223 216 7
RunMutatingTurn 160 158 2
SteadyStateReadOnlyTurn 159 155 4
SteadyStateReadParallelTurn 211 204 7
SteadyStateMutatingTurn 149 147 2

The pre-feature CI counts were 165, 214, 157, 154, 202, and 146 respectively. The remaining event-publication overhead is below the existing 2% threshold in every case.

The requested retry of main's performance run also failed, this time on scenario allocations. Five local samples after this fix produced these medians:

Scenario Pre-feature CI reference Failing main retry Fixed local median
BackgroundSubagents 807 824.5 811
CompactionCycle 3176 3304 3226
SingleSessionLong 33178.5 34691.5 33709

Those are cross-machine comparisons, not a latency claim or a substitute for PR CI. The fix adds 136 raw bytes of inline tracking per Run on amd64; long runs still use an overflow map. It does not claim universal memory/latency improvement.

Verification

Passed:

  • Full engine/agent tests and race tests.
  • Scoped agent lint.
  • Focused normal/race tests across eventsource, server gRPC/SSE/live subscription, telemetry, and ACP.
  • Negative control: removing overflow insertion makes the 9- and 32-ID regression cases fail; restored before final checks.
  • Complete task --concurrency 3 test:race.
  • Offline go run ./cmd/mecademo.
  • Full hot-path benchmark set: GOMAXPROCS=4 task bench BENCHCOUNT=5; existing perf/cmd/allocsgate passes against the fetched gh-pages reference without threshold/baseline changes.
  • Five samples of the three previously failing scenario benchmarks.
  • Formatting and git diff --check.

Local verification notes

GitHub CI passed Build and the complete non-race suite on 94c56cc19; Analysis and the performance gate were still running when checked. The PR is ready for review, enabling the full race/macOS CI jobs. The local observations below are retained for transparency, not additional conditions on PR readiness.

  • task --concurrency 3 test failed TestADR_0370_Scenario3_LiveOnlyProjection/grpc-disconnect: persisted 0 canonical results after disconnect. This is reproducible on unmodified baseline 6473fa341: 16 failures in 10,000 focused repetitions. The fixture cancels after observing the tool-call card, before execution necessarily starts; cancellation before the existing admission check can finish without a canonical result. The allocation patch does not alter that path. No assertion was weakened or retry added. The full race suite passed separately.
  • Full task lint twice exceeded the local 600-second command budget during root analysis (second attempt bounded GOMAXPROCS to 4). Scoped changed-package lint passed. Full lint is not claimed green.

Review

Reviewed commit 94c56cc19 against 6473fa341 across independent Spec, Standards, Test adequacy, Security, Architecture, Library reuse, and Duplication reviews. No classified findings. Reviewers inspected source; benchmark and executed-gate evidence is recorded separately above.

PANEL: ship_blockers=0 important=0 advisory=0 reviewer_failures=0

Keep common publication IDs inline, store batch publication state in existing records, and capture range-local worker indices without argument wrappers. Preserve run-wide deduplication, safe early publication, and canonical drain ordering.

Co-authored-by: Mecatl <[email protected]>
@JAORMX
JAORMX marked this pull request as ready for review October 1, 2026 06:15
@JAORMX
JAORMX merged commit 77e1ee5 into main Oct 1, 2026
62 of 64 checks passed
@JAORMX
JAORMX deleted the fix/tool-result-allocations branch October 1, 2026 07:16
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 1, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant