Streaming Serialization Methods for Memory-Efficient Large Subtree Processing#73
Merged
Merged
Conversation
Contributor
👋 Thanks, @freemans13!This pull request comes from a fork. For security, our CI runs in a restricted mode.
Thanks for contributing to bsv-blockchain/go-subtree! 🚀 |
mrz1836
requested changes
Dec 12, 2025
mrz1836
left a comment
Collaborator
There was a problem hiding this comment.
Few linter issues, see CI
auto-merge was automatically disabled
December 12, 2025 23:21
Head branch was pushed to by a user without write access
mrz1836
approved these changes
Dec 12, 2025
mrz1836
left a comment
Collaborator
There was a problem hiding this comment.
LGTM - however since this was a fork, tests and dep audit checks were not run. They will be run upon merging this branch.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Add Streaming Serialization Methods for Memory-Efficient Large Subtree Processing
Summary
Adds two new methods to
SubtreeDatathat enable memory-efficient streaming serialization and deserialization of transaction data. This allows applications to process very large subtrees (1M+ transactions) without loading all transactions into memory at once.Motivation
When processing large subtrees with millions of transactions, the existing
Serialize()andserializeFromReader()methods require all transactions to be in memory simultaneously. For production workloads with 1M transaction subtrees, this results in multi-GB memory usage per subtree.With multiple subtrees being processed concurrently, memory consumption becomes prohibitive, leading to OOM issues in production.
Changes
New Methods
WriteTransactionsToWriter(w io.Writer, startIdx, endIdx int) errorReadTransactionsFromReader(r io.Reader, startIdx, endIdx int) (int, error)Use Case
These methods enable a chunked processing pattern: