Background
In crates/outline/src/combined_extractor.rs, CombinedExtractors::extract currently uses an explicit pre-order (DFS) traversal via a stack to match top-level outline items and skip their descendants once matched.
Task
Explore whether switching to a level-order (BFS) traversal would be faster in practice. Potential advantages of BFS:
- Outline items (functions, classes, etc.) tend to cluster near the top levels of the AST, so BFS might find matches earlier and avoid allocating deep stack frames.
- The "skip descendants once matched" semantics may integrate naturally with a queue-based approach.
Potential drawbacks:
- BFS requires a queue/deque, which may have higher allocation overhead for deeply nested or wide ASTs.
- Pre-order with early skip may already be near-optimal for typical AST shapes.
Suggested investigation
- Benchmark both approaches on representative source files (Rust, TypeScript, Go) with the existing outline rules.
- Measure allocation count and throughput.
References
Requested by @HerringtonDarkholme.
Background
In
crates/outline/src/combined_extractor.rs,CombinedExtractors::extractcurrently uses an explicit pre-order (DFS) traversal via a stack to match top-level outline items and skip their descendants once matched.Task
Explore whether switching to a level-order (BFS) traversal would be faster in practice. Potential advantages of BFS:
Potential drawbacks:
Suggested investigation
References
Requested by @HerringtonDarkholme.