Skip to content

Oxc Transformer Alpha


Oxc transform(別名:transpile)のアルファ版リリースを発表し、お喜び申し上げます。

このリリースには以下の3つの主要機能が含まれています:

  1. TypeScript → ESNext への変換。
  2. React JSX → ESNext への変換(組み込みの React Refresh 機能付き)。
  3. TypeScript コンパイラを使用せずに、TypeScript Isolated Declarations DTS Emit を実行。

このアルファ段階では、ビルド時間を短縮するために、これらの機能を試していただくことをおすすめします。

私たちのベンチマーク の結果は以下の通りです:

  • 変換:Oxc は SWC より 3~5倍高速で、メモリ使用量が20%少なく、パッケージサイズも小さい(2 MB 対 SWC の 37 MB)。
  • 変換:Oxc は Babel より 20~50倍高速で、メモリ使用量が70%少なく、パッケージサイズが19 MB小さく、インストールする npm パッケージ数はわずか2つ(Babel では170個)。
  • React 開発 + React Refresh:Oxc は SWC より 5倍高速、Babel より 50倍高速。
  • TS isolated declarations .d.ts emit:Oxc は通常のファイルでは TSC より 40倍高速、大きなファイルでは 20倍高速。

使用例

oxc-transform npm パッケージ

現在、Vue.js はそのビルドパイプライン内で、孤立宣言用に oxc-transform npm パッケージを実験しています:

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

@lukeed および @maraisr は、自身のパッケージ empathic および dldr において oxc-transform を活用し、.d.ts1ステップで変換・生成しています。

以下の例は、1回の変換ステップで .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 の孤立宣言 .d.ts 出力機能を統合しています。

Rust oxc_transformer クレート

バンドラーの Rolldown は、oxc_transformer Rust クレートを直接利用しています。

ベンチマーク結果

ベンチマークの設定は 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)

孤立宣言

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

パッケージサイズ

Oxc はわずか 2 個の npm パッケージをダウンロードし、合計 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 の皆様に、ご慷慨なスポンサーシップをいただき、心より感謝申し上げます。