Oxc トランスフォーマのアルファ公開
Oxc の transform(トランスパイル)のアルファ版を公開します。
このリリースには大きな機能が三つ含まれます。
- TypeScript から ESNext への変換
- React JSX を ESNext へ。React Refresh 内蔵
- TypeScript コンパイラを使わず、TypeScript の Isolated Declarations による
.d.ts出力
アルファ段階のため、ビルド時間短縮の実験用途での利用を推奨します。
ベンチマーク では次のとおりです。
- 変換:Oxc は SWC の 3〜5 倍速、メモリは約 2 割削減、パッケージも小さい(2 MB 対 SWC の 37 MB)
- 変換:Oxc は Babel の 20〜50 倍速、メモリは約 7 割削減、19 MB 軽く、インストールは npm パッケージ 2 個だけ(Babel は 170 個)
- React 開発 + React Refresh:Oxc は SWC の 5 倍、Babel の 50 倍
- TS isolated declarations の
.d.ts出力:典型的なファイルでは Oxc は TSC の 40 倍速、大きめのファイルでも 20 倍速
利用例
npm パッケージ oxc-transform
Vue.js はビルドパイプラインで isolated declarations のために oxc-transform を試験導入中です。
import { isolatedDeclaration } from "oxc-transform";
const dts = isolatedDeclaration(filename, ts);@lukeed と @maraisr は、 empathic と dldr で oxc-transform を使い、 変換と .d.ts 生成を一つのステップで行っています。
次の例は、.js と .d.ts を一度の変換で出力します。
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 は esbuild プラグイン統合に unplugin-isolated-decl を利用しています。
@sxzz は .d.ts 生成時間が 76 秒から 16 秒になったと報告しています。
Airtable の Bazel ビルド
Airtable の @michaelm は、 Bazel ビルド内の CI で、Oxc の isolated declarations .d.ts 出力を統合しています。
Rust クレート oxc_transformer
バンドラの Rolldown は oxc_transformer クレートを直接利用しています。
ベンチマーク結果
セットアップは oxc-project/bench-transformer にあり、 結果は GitHub Actions で公開されています。
(設定の誤りがあれば修正の指摘を歓迎します。)
ubuntu-latest で、行数の異なるコードの一例:
変換
| 行数 | 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
| 行数 | 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) |
パッケージサイズ
Oxc がダウンロードする npm パッケージは合計 2 個、サイズは計 2 MB。
| パッケージ | サイズ |
|---|---|
@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 と 170 パッケージ |
メモリ使用量
Oxc はより少ないメモリを使います。
parser.ts(10777 行)を変換するときのメモリ(/usr/bin/time -alh node で計測):
| 最大 RSS | |
|---|---|
| oxc | 51 MB |
| swc | 67 MB |
| babel | 172 MB |
次のリリース
次のリリースには、ターゲットを ES6 へ下げる処理と @babel/plugin-transform-modules-commonjs 相当が含まれる予定です。
謝辞
今回のリリースに汗をかいてくれた @Dunqing と @overlookmotel に感謝します。
寛大な スポンサーシップ をくださった snyder.tech、schoolhouse.world、@lukeed、@maraisr にも感謝します。


