aspect-build / aspect-build/rules_swc
[Bug]: `jsc.experimental.cacheRoot` destroys SWC performance
- Dominant language
- Starlark
- Stars
- 49
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
### What happened?
Transpilation using SWC is incredibly slow if `swc_plugin()` is used.
Something about setting [`jsc.experimental.cacheRoot`](https://swc.rs/docs/configuration/compilation#jscexperimentalcacheroot) 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](https://github.com/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
```shell
See https://github.com/walkerburgin/rules_swc-plugin-cache-repro
```
### Any other information?
_No response_
Contributor guide
Research direction
Start with the swc_plugin() invocation and the jsc.experimental.cacheRoot setting described in the issue, then reproduce the behavior in walkerburgin/rules_swc-plugin-cache-repro. Compare bazel clean && bazel build //... with and without cacheRoot; done means SWC plugin builds no longer suffer the reported performance regression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100