💫

新しいNode.jsのモジュール管理ツール「Ultra」を試してみた

に公開

背景

Product Huntで少しだけ話題になっていたので、ちょっとだけ先走って試してみた。
https://www.producthunt.com/posts/ultra-241a7c40-a06f-450e-abac-321f614e6bee

Ultra とは

https://ultrapkg.dev/

NPM(Node Package Manager)の代わりとなる高速で軽量なツールです。
LinuxやMacOSでは既に動きますが、Windowsのサポートは開発中だそうです。
https://github.com/nachoaldamav/ultra/issues/40

※ まだこのツールは開発中なので、お試し期間っぽいです。

🚧 This project still in an early stage of development, for now you should only use it to test it.

なぜULTRAが速いのか

PNPMと同じインストール方式で、依存関係を取得し、残りの依存関係を待つことなくダウンロードしています。
各依存は .ultra-cache 内の共通のストアへのリンクになっているので、全てのプロジェクトでシェアして速くなっているっぽい。(具体的にはnode_modulesフォルダー内にパッケージへのハードリンクを作ってるらしい。)
https://ultrapkg.dev/docs/comparison

確かに ~/.ultra-cache を見てるっぽい。
https://github.com/nachoaldamav/ultra/blob/1e807739f43f7aff24323aaf92958bb25c243beb/packages/cli/src/utils/readConfig.ts#L7

globals.tsで global.userUltraCache に入れてるので、package installはこの辺りで見てそう。
https://github.com/nachoaldamav/ultra/blob/6c4a9681b49cb7150cd370c6cb753618b589f54c/packages/cli/src/utils/installPkg.ts#L70

インストール

npmでグローバルインストール

$ npm i ultra-pkg -g

Next.jsのテンプレートを作成してみる

$ ultra create next-app
[Ultra] v0.7.0 (169.76ms)
 Searching create-next-app in NPM Registry...
 Do you want to install create-next-app (v12.3.1)? … yes
 Downloading create-next-app...
 Installing create-next-app...
 What is your project named? ultra-next-app
Creating a new Next.js app in /Users/ta1m1kam/workspace/ultra-next-app.

ベンチマーク

上記で作ったNext.jsプロジェクトでUltraがgithub actionsで回してるbenchmarkを動かしてみた。
あれれ、MacOSでやるとあんまり速くないぞ...(笑)。

$ ultra benchmark
  Node.js: v18.10.0
  OS: darwin
  ULTRA version: 0.7.0
  Current project: ultra-next-app (0.1.0)


┌─────────┬─────────────────────────────────────────────────┬──────────┬───────┐
 (index) │                      name                       │   time   │ group │
├─────────┼─────────────────────────────────────────────────┼──────────┼───────┤
    0   'Bun install (with cache / with lockfile)' '0.05s'   3
    1   'YARN install (with cache / with lockfile)' '0.56s'   3
    2    'NPM install (with cache / no lockfile)' '1.06s'   2
    3 '⚡ ULTRA install (with cache / with lockfile)' '1.60s'   3
    4   'NPM install (with cache / with lockfile)' '1.63s'   3
    5  '⚡ ULTRA install (with cache / no lockfile)' '1.97s'   2
    6   'PNPM install (with cache / with lockfile)' '2.25s'   3
    7    'PNPM install (with cache / no lockfile)' '2.29s'   2
    8    'Bun install (with cache / no lockfile)' '3.53s'   2
    9     'Bun install (no cache / no lockfile)' '3.85s'   1
   10    'YARN install (with cache / no lockfile)' '4.86s'   2
   11     'NPM install (no cache / no lockfile)' '6.92s'   1
   12     'YARN install (no cache / no lockfile)' '26.31s'   1
   13     'PNPM install (no cache / no lockfile)' '28.55s'   1
   14   '⚡ ULTRA install (no cache / no lockfile)' '30.41s'   1
└─────────┴─────────────────────────────────────────────────┴──────────┴───────┘

公式では比較的速い。(こっちはlinuxなのでやはりOSの差かな? よくわからない)

  Node.js: v18.10.0
  OS: linux
  ULTRA version: 0.6.9
  Current project: next-ultra (0.1.0)

┌─────────┬─────────────────────────────────────────────────┬──────────┬───────┐
 (index) │                      name                       │   time   │ group │
├─────────┼─────────────────────────────────────────────────┼──────────┼───────┤
    0   'Bun install (with cache / with lockfile)' '0.17s'   3
    1   'ULTRA install (with cache / with lockfile)' '0.92s'   3
    2    'ULTRA install (with cache / no lockfile)' '1.12s'   2
    3   'PNPM install (with cache / with lockfile)' '3.34s'   3
    4    'PNPM install (with cache / no lockfile)' '4.58s'   2
    5   'YARN install (with cache / with lockfile)' '5.12s'   3
    6   'NPM install (with cache / with lockfile)' '6.02s'   3
    7    'Bun install (with cache / no lockfile)' '6.74s'   2
    8    'NPM install (with cache / no lockfile)' '7.81s'   2
    9     'Bun install (no cache / no lockfile)' '17.12s'   1
   10     'ULTRA install (no cache / no lockfile)' '17.83s'   1
   11     'PNPM install (no cache / no lockfile)' '18.45s'   1
   12    'YARN install (with cache / no lockfile)' '21.30s'   2
   13     'NPM install (no cache / no lockfile)' '24.26s'   1
   14     'YARN install (no cache / no lockfile)' '49.79s'   1
└─────────┴─────────────────────────────────────────────────┴──────────┴───────┘

https://github.com/nachoaldamav/ultra/pulls?q=is%3Apr+is%3Aclosed
直近のPRではgithub actionsが自動でbenchmark取ってPRにコメントしているようなので確認してみてください。

darwinは今後に期待ということで...。

参考

https://github.com/nachoaldamav/ultra

Discussion