Skip to content

[state-prune snapshot] Switch traversal worklist from BFS (VecDeque) to DFS (Vec) to reduce peak memory #3872

@jolestar

Description

@jolestar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions