Skip to content

Oxc トランスフォーマのアルファ公開


Oxc の transform(トランスパイル)のアルファ版を公開します。

このリリースには大きな機能が三つ含まれます。

  1. TypeScript から ESNext への変換
  2. React JSX を ESNext へ。React Refresh 内蔵
  3. 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試験導入中です。

javascript
import { isolatedDeclaration } from "oxc-transform";
const dts = isolatedDeclaration(filename, ts);

@lukeed@maraisr は、 empathicdldroxc-transform を使い、 変換と .d.ts 生成を一つのステップで行っています。

次の例は、.js.d.ts を一度の変換で出力します。

javascript
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

バンドラの Rolldownoxc_transformer クレートを直接利用しています。

ベンチマーク結果

セットアップは oxc-project/bench-transformer にあり、 結果は GitHub Actions で公開されています。

(設定の誤りがあれば修正の指摘を歓迎します。)

ubuntu-latest で、行数の異なるコードの一例:

変換

行数oxcswcbabel
~1000.14 ms0.7 ms (5x)11.5 ms (82x)
~10000.9 ms5.7 ms (6.3x)38.7 ms (43x)
~1000014.9 ms35.9 ms(2.4x)492 ms (33x)

Isolated Declarations

行数oxctsc
~1000.1 ms23.1 ms (231x)
~10003.1 ms26.8 ms (8.6x)
~100003.5 ms115.2 ms (33x)

パッケージサイズ

Oxc がダウンロードする npm パッケージは合計 2 個、サイズは計 2 MB。

パッケージサイズ
@oxc-transform/binding-darwin-arm642.0 MB
@swc/core-darwin-arm6437.5 MB
@babel/core + @babel/preset-env + @babel/preset-react + @babel/preset-typescript21 MB と 170 パッケージ

メモリ使用量

Oxc はより少ないメモリを使います。

parser.ts(10777 行)を変換するときのメモリ(/usr/bin/time -alh node で計測):

最大 RSS
oxc51 MB
swc67 MB
babel172 MB

次のリリース

次のリリースには、ターゲットを ES6 へ下げる処理と @babel/plugin-transform-modules-commonjs 相当が含まれる予定です。

謝辞

今回のリリースに汗をかいてくれた @Dunqing@overlookmotel に感謝します。

寛大な スポンサーシップ をくださった snyder.techschoolhouse.world@lukeed@maraisr にも感謝します。