Skip to content

opt: buffer reuse in trace_agent to_bytes#1783

Draft
preinlein wants to merge 1 commit intomainfrom
opt/trace-agent-buffer-reuse
Draft

opt: buffer reuse in trace_agent to_bytes#1783
preinlein wants to merge 1 commit intomainfrom
opt/trace-agent-buffer-reuse

Conversation

@preinlein
Copy link
Contributor

Summary

  • Replaced per-iteration Vec::with_capacity(max_bytes) allocations in V04::to_bytes growth loop, binary search loop, and final serialization with a single reusable buffer cleared via .clear()
  • Eliminates ~15-20 redundant allocations of up to max_bytes each per to_bytes call

Benchmark Results

Micro-benchmarks (criterion)

  • trace_agent_throughput/10MiB: -3.6% time / +3.7% throughput (p<0.05, "Performance has improved")
  • trace_agent_throughput/100MiB: -2.6% time / +2.7% throughput (p<0.05, "Performance has improved")

Macro-benchmarks (payloadtool)

  • Time: ~0% (dominated by payloadtool startup overhead)
  • Memory: -65.6% (33.51 MiB -> 11.51 MiB total allocated)
  • Allocations: -1.2% (18,142 -> 17,922)
  • Peak live: unchanged (2.78 MiB)

Validation

  • ci/validate passes (including Kani proofs)
  • All 12 trace_agent property tests pass
  • 5/5 review personas approve

🤖 Generated with Claude Code

Replaced per-iteration Vec::with_capacity(max_bytes) in the growth
loop, binary search loop, and final serialization with a single
reusable buffer cleared via .clear().

Target: lading_payload/src/trace_agent/v04.rs::V04::to_bytes
Technique: buffer-reuse

Micro-benchmarks:
  trace_agent_throughput/10MiB: -3.6% time / +3.7% throughput
  trace_agent_throughput/100MiB: -2.6% time / +2.7% throughput

Macro-benchmarks (payloadtool):
  Time: ~0% (dominated by payloadtool overhead)
  Memory: -65.6% (33.51 MiB -> 11.51 MiB total allocated)
  Allocations: -1.2% (18,142 -> 17,922)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@preinlein preinlein requested a review from a team as a code owner February 20, 2026 21:38
@preinlein preinlein marked this pull request as draft February 20, 2026 21:38
@preinlein
Copy link
Contributor Author

Moved this back to draft, it's an optimization run using the latest skills.

I want to make sure that any subsequent runs don't target any in flight optimizations and I need something "pending".

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