Skip to content

perf(ast_tools): parse files in parallel#20578

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/02-14-perf_ast_tools_parse_files_in_parallel
Mar 20, 2026
Merged

perf(ast_tools): parse files in parallel#20578
graphite-app[bot] merged 1 commit intomainfrom
om/02-14-perf_ast_tools_parse_files_in_parallel

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Mar 20, 2026

#20577 made ast_tools search for and parse all files in all crates that depend on oxc_ast_macros.

The one downside of this change is that it makes running ast_tools slower.

Speed it up again, by parsing files in parallel, using rayon.

There is one annoyance. Due to feature unification, syn crate gets compiled with proc-macro feature enabled, which makes syns ASTs not Send. We don't use the AST in ways which can produce data races (and we can't, because ast_tools isn't a proc macro), so it is safe in practice to send ASTs across threads here. So we have to hack it to make it compile (see comment in tasks/ast_tools/src/parse/mod.rs).

Copy link
Copy Markdown
Member Author

overlookmotel commented Mar 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Speeds up oxc_ast_tools schema construction by parallelizing the phase-1 file parsing across crates/files, while keeping deterministic ordering for generated TypeId/MetaId indexing.

Changes:

  • Parse/load Rust files in parallel via rayon::par_iter() and then merge results sequentially to preserve deterministic ordering.
  • Refactor phase-1 collection to use FxIndexSet + IndexVec instead of FxIndexMap for skeleton storage and name indexing.
  • Adjust syn feature flags and introduce an unsafe Send wrapper to allow transferring syn ASTs between threads.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tasks/ast_tools/src/parse/mod.rs Parallelizes file loading and introduces the AssertSend wrapper for syn AST transfer.
tasks/ast_tools/src/parse/load.rs Changes load_file to return per-file skeleton results instead of mutating shared maps.
tasks/ast_tools/src/parse/parse.rs Updates parse() signature to accept sets/vectors aligned with new phase-1 data structures.
tasks/ast_tools/Cargo.toml Updates syn feature selection (drops proc-macro explicitly).

@overlookmotel overlookmotel self-assigned this Mar 20, 2026
@overlookmotel overlookmotel force-pushed the om/02-14-perf_ast_tools_parse_files_in_parallel branch from 93f5bde to c66b283 Compare March 20, 2026 22:02
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 20, 2026
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Mar 20, 2026

Merge activity

#20577 made `ast_tools` search for and parse all files in all crates that depend on `oxc_ast_macros`.

The one downside of this change is that it makes running `ast_tools` slower.

Speed it up again, by parsing files in parallel, using `rayon`.

There is one annoyance. Due to feature unification, `syn` crate gets compiled with `proc-macro` feature enabled, which makes `syn`s ASTs not `Send`. We don't use the AST in ways which can produce data races (and we can't, because `ast_tools` isn't a proc macro), so it is safe in practice to send ASTs across threads here. So we have to hack it to make it compile (see comment in `tasks/ast_tools/src/parse/mod.rs`).
@graphite-app graphite-app bot force-pushed the om/02-14-refactor_ast_tools_search_all_crates_which_depend_on_oxc_ast_macros_ branch from 98a1757 to 1be1ebe Compare March 20, 2026 22:16
@graphite-app graphite-app bot requested a review from camc314 as a code owner March 20, 2026 22:16
@graphite-app graphite-app bot force-pushed the om/02-14-perf_ast_tools_parse_files_in_parallel branch from c66b283 to 82a136f Compare March 20, 2026 22:16
Base automatically changed from om/02-14-refactor_ast_tools_search_all_crates_which_depend_on_oxc_ast_macros_ to main March 20, 2026 22:22
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 20, 2026
@graphite-app graphite-app bot merged commit 82a136f into main Mar 20, 2026
24 checks passed
@graphite-app graphite-app bot deleted the om/02-14-perf_ast_tools_parse_files_in_parallel branch March 20, 2026 22:23
costajohnt pushed a commit to costajohnt/oxc that referenced this pull request Mar 22, 2026
oxc-project#20577 made `ast_tools` search for and parse all files in all crates that depend on `oxc_ast_macros`.

The one downside of this change is that it makes running `ast_tools` slower.

Speed it up again, by parsing files in parallel, using `rayon`.

There is one annoyance. Due to feature unification, `syn` crate gets compiled with `proc-macro` feature enabled, which makes `syn`s ASTs not `Send`. We don't use the AST in ways which can produce data races (and we can't, because `ast_tools` isn't a proc macro), so it is safe in practice to send ASTs across threads here. So we have to hack it to make it compile (see comment in `tasks/ast_tools/src/parse/mod.rs`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants