Skip to content

[turbopack] Use ast_path.kinds() instead of mapping over ast_path in the analyzer#94221

Merged
sampoder merged 1 commit into
turbopack-analyzer-negative-numbersfrom
sp/turbopack_analyzer_ast_path_kinds
May 30, 2026
Merged

[turbopack] Use ast_path.kinds() instead of mapping over ast_path in the analyzer#94221
sampoder merged 1 commit into
turbopack-analyzer-negative-numbersfrom
sp/turbopack_analyzer_ast_path_kinds

Conversation

@sampoder
Copy link
Copy Markdown
Member

@sampoder sampoder commented May 29, 2026

@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:

Screenshot 2026-05-29 at 12 24 41 AM

Interestingly, SWC also appears to be calculating this information based on the call stack. And it appears that SWC's AstNodePath's kinds() method 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Tests Passed

Commit: 6896fc7

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Stats skipped

Commit: 6896fc7
View workflow run

Copy link
Copy Markdown
Contributor

@lukesandberg lukesandberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing

@sampoder sampoder force-pushed the turbopack-analyzer-negative-numbers branch from 91a6ffa to f1fdb47 Compare May 29, 2026 20:11
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch from feb80ef to 98c9490 Compare May 29, 2026 20:11
@sampoder sampoder force-pushed the turbopack-analyzer-negative-numbers branch from f1fdb47 to 8c145b1 Compare May 29, 2026 20:37
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch from 98c9490 to 38c18ab Compare May 29, 2026 20:37
@sampoder sampoder force-pushed the turbopack-analyzer-negative-numbers branch 2 times, most recently from e8c3f45 to bac9ce7 Compare May 29, 2026 22:25
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch 3 times, most recently from 5693ec6 to 70bac01 Compare May 29, 2026 22:31
@sampoder sampoder force-pushed the turbopack-analyzer-negative-numbers branch 2 times, most recently from 1a42441 to 3f17609 Compare May 29, 2026 23:20
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch from 70bac01 to 254fe0d Compare May 29, 2026 23:20
@sampoder sampoder force-pushed the turbopack-analyzer-negative-numbers branch from 3f17609 to 0019d3a Compare May 30, 2026 00:12
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch from 254fe0d to 3012de3 Compare May 30, 2026 00:14
@sampoder sampoder force-pushed the sp/turbopack_analyzer_ast_path_kinds branch from 3012de3 to 6896fc7 Compare May 30, 2026 00:15
@sampoder sampoder marked this pull request as ready for review May 30, 2026 01:50
@sampoder sampoder merged commit 2bbb67b into canary May 30, 2026
282 of 297 checks passed
@sampoder sampoder deleted the sp/turbopack_analyzer_ast_path_kinds branch May 30, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants