Skip to content

perf: streaming subtree serialization with go-bt v2.6.0#100

Merged
icellan merged 2 commits into
masterfrom
perf/streaming-subtree-serialization
Feb 27, 2026
Merged

perf: streaming subtree serialization with go-bt v2.6.0#100
icellan merged 2 commits into
masterfrom
perf/streaming-subtree-serialization

Conversation

@icellan
Copy link
Copy Markdown
Contributor

@icellan icellan commented Feb 27, 2026

Summary

  • Use SerializeTo (from go-bt v2.6.0) to stream transaction data directly to the writer during subtree serialization, eliminating intermediate []byte allocations
  • Upgrade go-bt from v2.5.3 to v2.6.0

Performance Impact

When serializing subtrees for a 3.64 GB testnet block (28,672 transactions), this change eliminates the per-transaction Bytes() allocation in SerializeSubtree. Combined with go-bt's new WriteTo methods, the full serialization path now writes directly to the output writer without intermediate buffers.

Measured on HandleBlockDirect with block 1681787:

  • Subtree serialization allocations reduced by ~51% vs the previous Bytes()-based approach

Test plan

  • All go-subtree tests pass
  • Integration test with teranode HandleBlockDirect

Replace SerializeBytes() + Write() with SerializeTo(w) in
WriteTransactionsToWriter, writing transaction data directly to the
io.Writer without allocating intermediate byte slices.

This eliminates per-tx Output.Bytes() and Input.ExtendedBytes()
allocations during subtree serialization. For a 3.64 GB block
(28,672 txs), this reduced HandleBlockDirect allocations by ~10.6 GB.

Depends on go-bt SerializeTo method (bsv-blockchain/go-bt#117).
Update go-bt dependency to v2.6.0 which adds zero-allocation WriteTo/
SerializeTo methods. The subtree serialization now uses SerializeTo to
stream transaction data directly to the writer instead of allocating
intermediate byte slices.
@icellan icellan requested a review from mrz1836 as a code owner February 27, 2026 13:44
@github-actions github-actions Bot added size/S Small change (11–50 lines) performance Performance improvements or optimizations labels Feb 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

@icellan icellan requested review from oskarszoon and removed request for mrz1836 February 27, 2026 13:45
@icellan icellan merged commit 1004ee6 into master Feb 27, 2026
49 checks passed
@github-actions github-actions Bot deleted the perf/streaming-subtree-serialization branch February 27, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance improvements or optimizations size/S Small change (11–50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants