Parent: #3858
Background
Current SnapshotBuilder traversal in crates/rooch-pruner/src/state_prune/snapshot_builder.rs uses BFS with VecDeque (pop_front/push_back). For large and/or wide SMT graphs, the queue can grow very large (O(width) / potentially O(n)), which increases peak memory and may reintroduce memory pressure even after streaming writes.
Goal
Change traversal to DFS using a stack (Vec) to bound the worklist size closer to O(depth) (SMT depth is typically small and bounded), reducing peak memory usage.
Scope
- Replace
VecDeque BFS queue with Vec stack in traversal.
- Keep snapshot semantics unchanged (still visits all reachable nodes).
- Keep current dedup strategy and writer behavior unchanged (this is a focused memory fix).
Acceptance
- Traversal uses DFS stack (
Vec) and does not allocate a large VecDeque queue.
- No correctness regression: snapshot completeness preserved.
- Existing tests pass.
Parent: #3858
Background
Current
SnapshotBuildertraversal incrates/rooch-pruner/src/state_prune/snapshot_builder.rsuses BFS withVecDeque(pop_front/push_back). For large and/or wide SMT graphs, the queue can grow very large (O(width) / potentially O(n)), which increases peak memory and may reintroduce memory pressure even after streaming writes.Goal
Change traversal to DFS using a stack (
Vec) to bound the worklist size closer to O(depth) (SMT depth is typically small and bounded), reducing peak memory usage.Scope
VecDequeBFS queue withVecstack in traversal.Acceptance
Vec) and does not allocate a largeVecDequequeue.