next.js
2bbb67b9 - [turbopack] Use `ast_path.kinds()` instead of mapping over `ast_path` in the analyzer (#94221)

Commit
85 days ago
[turbopack] Use `ast_path.kinds()` instead of mapping over `ast_path` in the analyzer (#94221) @lukesandberg and I were looking at the call stack for the analyzer this morning and we talked about how we appeared to be spending a lot of time calculating the kind of each node's parent, see: <img width="939" height="291" alt="Screenshot 2026-05-29 at 12 24 41 AM" src="https://github.com/user-attachments/assets/1f9d2c02-0a49-4e33-8107-626791e85ba1" /> Interestingly, SWC also appears to be calculating this information based on the call stack. And it appears that SWC's [`AstNodePath`'s `kinds()` method](https://rustdoc.swc.rs/swc_common/pass/struct.AstNodePath.html#method.kinds) is a pre-computed version of what we were computing. This PR switches us to using that method to see if there any potential performance benefits. I think I need a little bit of help benchmarking this more but running: ``` cargo bench --manifest-path /Users/sampoder/dev/next.js/Cargo.toml -p turbopack-ecmascript --bench analyzer -- --baseline orig 'create_graph/(peg|react-dom-production|md5)' ``` First on the branch without this switch, and then on this branch suggests improvements: ``` analyzer/create_graph/md5 time: [109.87 µs 110.24 µs 110.59 µs] change: [-3.3365% -2.7341% -2.1580%] (p = 0.00 < 0.05) Performance has improved. analyzer/create_graph/peg time: [1.3740 ms 1.3813 ms 1.3887 ms] change: [-8.4332% -7.7685% -7.1580%] (p = 0.00 < 0.05) Performance has improved. analyzer/create_graph/react-dom-production time: [2.9095 ms 2.9319 ms 2.9553 ms] change: [-17.616% -16.642% -15.677%] (p = 0.00 < 0.05) Performance has improved. Found 7 outliers among 100 measurements (7.00%) 7 (7.00%) high mild analyzer/create_graph/md5-reduced time: [26.658 µs 26.725 µs 26.794 µs] change: [-5.7610% -5.2585% -4.7925%] (p = 0.00 < 0.05) Performance has improved. Found 4 outliers among 100 measurements (4.00%) 3 (3.00%) high mild 1 (1.00%) high severe analyzer/create_graph/md5_2 time: [109.99 µs 110.30 µs 110.64 µs] change: [-9.0036% -8.5102% -8.0469%] (p = 0.00 < 0.05) Performance has improved. Found 3 outliers among 100 measurements (3.00%) 3 (3.00%) high mild ```
Author
Parents
Loading