Commit fb6a139
committed
perf: replace manual AST walk with tree-sitter Query API for JS/TS/TSX extraction
WASM build speed regressed from 5.0 ms/file (v2.0.0) to 6.6 ms/file (v2.1.0+)
due to excessive WASM-JS boundary crossings in the JS extractor — every
node.type, .text, .childForFieldName() call crosses the boundary.
Phase 1 — cache redundant boundary crossings:
- Fix findChild() calling node.child(i) twice per match
- Cache node.type, node.startPosition.row, prop.text into locals across
class_declaration, export_statement, extractCallInfo, walkCallChain,
findParentClass, and variable_declaration cases
Phase 2 — tree-sitter Query API extraction:
- Import Query from web-tree-sitter, compile S-expression patterns per
language (JS vs TS/TSX) during createParsers(), cache in module-level Map
- New extractSymbolsQuery() uses query.matches(rootNode) to run pattern
matching entirely inside WASM, reducing boundary crossings from
O(nodes × properties) to O(matches × captures)
- Post-processing only runs on matched nodes (tens per file) not all AST
nodes (thousands per file)
- Manual tree walk preserved as fallback for backward compatibility when
query is not provided
Result: 6.6 → 4.4 ms/file (−33%), below v2.0.0 baseline of 5.0 ms/file.
All 536 tests pass, node/edge counts identical.
Impact: 12 functions changed, 20 affected1 parent ab0d3a0 commit fb6a139
3 files changed
Lines changed: 335 additions & 81 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
0 commit comments