Skip to content

perf: macOS AST cloning is sequential in incremental builds #8630

@Boshen

Description

@Boshen

Context

In crates/rolldown/src/stages/scan_stage.rs:64-67, the make_copy() method used for incremental builds disables parallel iteration on macOS:

#[cfg(not(target_os = "macos"))]
let iter = self.index_ecma_ast.raw.par_iter();
#[cfg(target_os = "macos")]
let iter = self.index_ecma_ast.raw.iter();

let index_ecma_ast = iter
    .map(|ast| ast.as_ref().map(rolldown_ecmascript::EcmaAst::clone_with_another_arena))
    .collect::<Vec<_>>();

clone_with_another_arena is an expensive operation (it clones the entire AST into a new allocator arena), and running it sequentially on macOS is a significant performance bottleneck for incremental builds. On non-macOS platforms, par_iter() is used, which distributes the cloning across threads.

Need to investigate why par_iter was disabled on macOS (likely an allocator or thread-safety issue with the arena allocator on macOS) and determine if it can be safely re-enabled.

Metadata

Metadata

Assignees

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions