Skip to content

[Bug]: jsc.experimental.cacheRoot destroys SWC performance #293

@walkerburgin

Description

@walkerburgin

What happened?

Transpilation using SWC is incredibly slow if swc_plugin() is used.

Something about setting jsc.experimental.cacheRoot inside of the Bazel sandbox when invoking SWC is absolutely destroying performance.

I put together a standalone repro here: walkerburgin/rules_swc-plugin-cache-repro using the @swc/plugin-noop.

➜  hyperfine --runs 5 'bazel clean && bazel build //...'
Benchmark 1: bazel clean && bazel build //...
  Time (mean ± σ):     26.342 s ±  0.855 s    [User: 0.182 s, System: 0.076 s]
  Range (min … max):   25.613 s … 27.800 s    5 runs

If I patch aspect_rules_swc to stop specifying jsc.experimental.cacheRoot:

Benchmark 1: bazel clean && bazel build //...
  Time (mean ± σ):      8.647 s ±  0.229 s    [User: 0.177 s, System: 0.070 s]
  Range (min … max):    8.346 s …  8.939 s    5 runs

The effect in our codebase using an actual plugin is much, much more pronounced. It slows typescript transpilation down by something like +500x and slows my machine to a crawl.

It feels like there's an SWC bug related to symlinks at the heart of this…

Version

Development (host) and target OS/architectures: darwin-arm64

Output of bazel --version:

➜  rules_swc-plugin-cache-repro git:(master) bazel --version
aspect 2025.05.46+36b9b384e

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

bazel_dep(name = "aspect_rules_js", version = "2.1.1")
bazel_dep(name = "aspect_rules_ts", version = "3.3.1")
bazel_dep(name = "aspect_rules_swc", version = "2.3.0")

Language(s) and/or frameworks involved:

  • SWC
  • TypeScript

How to reproduce

See https://github.com/walkerburgin/rules_swc-plugin-cache-repro

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingengagement noterelated to an Aspect engagement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions