Skip to content

TODO: Explore whether level-order (BFS) traversal is faster than pre-order in CombinedExtractors::extract #2736

Description

@coderabbitai

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions