`import "typescript"` slower than `require("typescript")` due to `cjs-module-lexer` overhead
オープン
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
- Node.js v24.8.0
- Node.js v22.18.0
Platform
Observed on macOS (x64), but likely reproducible on other platforms.
Description
When loading typescript, using import is ~100ms slower than require.
This seems to come from the cjs-module-lexer step Node.js runs for CommonJS packages. Since typescript itself is CommonJS, require avoids the overhead and is noticeably faster.
Reproduction
https://github.com/chenjiahan/nodejs-repro-require-import-typescript
// import.mjs
import typescript from "typescript";
console.log(typescript);
// require.cjs
const typescript = require("typescript");
console.log(typescript);
Example results (macOS, Node.js v24.8.0):
# ~200ms
time node ./import.mjs
# ~100ms
time node ./require.cjs
Ref
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた再現手順から始め、提供された計測コマンドを使用して、Node.js v24.8.0 および v22.18.0 上で import.mjs と require.cjs を比較します。CommonJS パッケージ typescript について報告されている cjs-module-lexer のオーバーヘッドを調査します。完了の条件は、パフォーマンス差が再現・説明され、提案されたスコープがあればそれが文書化されていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js, typescript
- 領域
- performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 42/100