Oxc Transformer Alpha
We are excited to announce an alpha release for Oxc transform (a.k.a transpile).
This release contains three major features:
- Transforming TypeScript to ESNext.
- Transforming React JSX to ESNext, with built-in React Refresh.
- TypeScript Isolated Declarations DTS Emit without using the TypeScript compiler.
In this alpha stage, we recommend to experiment with these features to speed up build times.
Our benchmark shows:
- Transform: Oxc is 3x - 5x faster than SWC, uses 20% less memory, and has smaller package size (2 MB vs SWC's 37 MB).
- Transform: Oxc is 20x - 50x faster than Babel, uses 70% less memory, and is 19 MB smaller, with only 2 npm packages to install vs Babel's 170.
- React development + React Refresh: Oxc is 5x faster than SWC, 50x faster than Babel.
- TS isolated declarations
.d.ts
emit: Oxc is 40x faster than TSC on typical files, 20x faster on larger files.
Usage Examples
oxc-transform
npm package
Vue.js is currently experimenting the oxc-transform
npm package for isolated declarations in its build pipeline:
import { isolatedDeclaration } from "oxc-transform";
const dts = isolatedDeclaration(filename, ts);
@lukeed and @maraisr are utilizing oxc-transform
for their packages empathic
and dldr
to transform and generate .d.ts
in a single step.
The following example demonstrates emitting .js
and .d.ts
in a single transformation step:
import { transform } from "oxc-transform";
const transformed = transform(filePath, sourceCode, {
typescript: {
onlyRemoveTypeImports: true,
declaration: { stripInternal: true },
},
});
await fs.writeFile("out.js", transformed.code);
await fs.writeFile("out.d.ts", transformed.declaration);
unplugin-isolated-decl
vue-macros
uses unplugin-isolated-decl
as the integration tool for its esbuild plugin.
@sxzz reports their .d.ts
generation time is reduced from 76s to 16s.
Bazel build at Airtable
@michaelm from Airtable is integrating Oxc's isolated declarations .d.ts
emit in their CI pipeline within their Bazel build.
Rust oxc_transformer
crate
The Rolldown bundler uses the oxc_transformer
Rust crate directly.
Benchmark Results
The benchmark setup is located at oxc-project/bench-transformer and the benchmarks are shown in its GitHub Actions.
(Corrections are welcome for any misconfigurations.)
On ubuntu-latest
, an example of different lines of code are measured:
Transform
Lines | oxc | swc | babel |
---|---|---|---|
~100 | 0.14 ms | 0.7 ms (5x) | 11.5 ms (82x) |
~1000 | 0.9 ms | 5.7 ms (6.3x) | 38.7 ms (43x) |
~10000 | 14.9 ms | 35.9 ms(2.4x) | 492 ms (33x) |
Isolated Declarations
Lines | oxc | tsc |
---|---|---|
~100 | 0.1 ms | 23.1 ms (231x) |
~1000 | 3.1 ms | 26.8 ms (8.6x) |
~10000 | 3.5 ms | 115.2 ms (33x) |
Package size
Oxc downloads only 2 npm packages, a total of 2 MB.
Package | Size |
---|---|
@oxc-transform/binding-darwin-arm64 | 2.0 MB |
@swc/core-darwin-arm64 | 37.5 MB |
@babel/core + @babel/preset-env + @babel/preset-react + @babel/preset-typescript | 21 MB and 170 packages |
Memory Usage
Oxc uses less memory.
Memory usage transforming parser.ts
(10777 lines) - measured using /usr/bin/time -alh node
:
Max RSS | |
---|---|
oxc | 51 MB |
swc | 67 MB |
babel | 172 MB |
Next Release
Our next release will include target lowering to ES6 and @babel/plugin-transform-modules-commonjs
.
Acknowledgements
Thank you @Dunqing and @overlookmotel for all the hard work involved in this release.
Thank you snyder.tech, schoolhouse.world, @lukeed and @maraisr for the generous sponsorship.