yossydev Blog

yossy.devでisolatedDeclationを有効にしてtscの速度を測る

publishedAt:
2024/12/16
updatedAt:
2024/12/16
目次

2024年 ユウトの一人アドベントカレンダーの16日目の記事です。

Intro

Isolated Declarationsを有効にして、速度を測ってみました。

進め方

"isolatedDeclarations": trueを設定するだけで良いです。プロジェクトによっては、--declarationも有効にする必要があるかもしれません。

あとは大量のエラーと戦うだけです。本ブログに関しては、以下のようなエラー数でした。

Errors  Files
     1  app/hooks/useDebounce.ts:3
     1  app/libs/date.ts:7
     3  app/libs/rss/rss.ts:14
     1  app/libs/vite-remark-toc-plugin.ts:9
     1  app/routes/_renderer.tsx:5
     1  app/routes/all/index.tsx:16
     1  app/routes/index.tsx:5
     1  app/routes/posts/_renderer.tsx:6
     1  app/routes/profile/index.tsx:10
     1  app/routes/slides/index.tsx:7
     1  app/routes/youtube/index.tsx:7
     1  app/server.ts:4
     1  vite.config.ts:14

ただvscodeは優秀なので、⌘ + .でいい感じに型をつけてくれるので、それにほぼ頼りました。 実際にはそれなりにちゃんとみたほうがいいと思います。

結果

実際にコード上でどんな変更をしたかは、https://github.com/yossydev/yossy.dev/pull/78/files#diff-87e9aecc3694701f8eaef8ed0938745a89219c6d60a3b30f7ae9c44dc6761490で確認できます。

そして、"typecheck:perfomance": "tsc --generateTrace . --incremental false --noEmit"ってスクリプトを追加して、速度のチェックを行いました。

ここで生成されるtrace.jsonを、chrome://tracingの右上にあるLoadボタンで読み込ませて確認しています。

無効時

  1. 804ms
  2. 757ms
  3. 822ms
  4. 791ms
imageimageimageimage

有効時

  1. 865ms
  2. 773ms
  3. 773ms
  4. 787ms
imageimageimageimage

全然コード量も多くないし、複雑な推論も必要な処理していないので誤差ですね。

まとめ

Isolated Declarationsを有効化していくOSSや、サービスも多くなっていくと思うので、なんとなく素振りができてよかったです。

0