`RedisClientType` type is slow to typecheck (TS performance issue)
メンテナーはふだん 1 日以内に返信
@nkaradzhov がすでに取り組んでいます。
2025年5月27日 から。
評価
この issue はまだ評価されていません。
説明
Description
We just upgraded redis from 4.7.0 to 5.1.0. In our CI we have a job to verify that all types are still correct (using tsc --noEmit). Since upgrading redis this job now runs out of memory:
CI log
> tsc --noEmit -p tsconfig.test.json
<--- Last few GCs --->
[47:0x7d3f4fbaf000] 79561 ms: Mark-Compact 2043.8 (2085.9) -> 2042.7 (2086.9) MB, pooled: 0 MB, 2499.84 / 0.00 ms (average mu = 0.093, current mu = 0.008) allocation failure; scavenge might not succeed
[47:0x7d3f4fbaf000] 82274 ms: Mark-Compact 2044.7 (2086.9) -> 2043.6 (2087.9) MB, pooled: 0 MB, 2692.69 / 0.00 ms (average mu = 0.049, current mu = 0.007) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
ELIFECYCLE Command failed.
Aborted (core dumped)
I can reproduce this locally using NODE_OPTIONS="--max-old-space-size=2048" pnpm tsc --noEmit -p tsconfig.test.json (this does also include our application code, so the max size is probably different for a small reproduction).
I analyzed the output on my local machine (Macbook M3 Pro, 36GB RAM) using @typescript/analyze-trace, which gave the following output:
Hot Spots
└─ Check file [35m/project/test/test-helpers/[36mmocks.ts[39m[35m[39m (2747ms)
└─ Check expression from (line 21, char 5) to (line 23, char 7) (2734ms)
└─ Check expression from (line 21, char 18) to (line 23, char 7) (2717ms)
└─ Determine variance of type 335076 (2638ms)
└─ Compare types 689415 and 689406 (1366ms)
└─ Compare types 689415 and 689398 (1366ms)
└─ Compare types 689407 and 689398 (1330ms)
├─ {"id":689407,"kind":"GenericTypeAlias","name":"WithCommands","aliasTypeArguments":[335026,335036,335037,335038,47,335040],"location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":9,"char":1}}
│ ├─ {"id":335026,"kind":"TypeParameter","name":"REPLIES","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":41}}
│ ├─ {"id":335036,"kind":"TypeParameter","name":"M","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":69}}
│ ├─ {"id":335037,"kind":"TypeParameter","name":"F","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":93}}
│ ├─ {"id":335038,"kind":"TypeParameter","name":"S","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":119}}
│ ├─ {"id":47,"kind":"TypeParameter"}
│ └─ {"id":335040,"kind":"TypeParameter","name":"TYPE_MAPPING","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":170}}
└─ {"id":689398,"kind":"GenericTypeAlias","name":"WithCommands","aliasTypeArguments":[335026,335036,335037,335038,46,335040],"location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":9,"char":1}}
├─ {"id":335026,"kind":"TypeParameter","name":"REPLIES","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":41}}
├─ {"id":335036,"kind":"TypeParameter","name":"M","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":69}}
├─ {"id":335037,"kind":"TypeParameter","name":"F","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":93}}
├─ {"id":335038,"kind":"TypeParameter","name":"S","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":119}}
├─ {"id":46,"kind":"TypeParameter"}
└─ {"id":335040,"kind":"TypeParameter","name":"TYPE_MAPPING","location":{"path":"[35m/project/node_modules/[36m.pnpm[39m[35m/@[email protected]/node_modules/[36m@redis/client[39m[35m/dist/lib/client/multi-command.d.ts[39m","line":25,"char":170}}
This led me to a file used in our tests:
Affected code (unrelated code omitted for brevity)
// test/test-helpers/mocks.ts
import { createClient, type RedisClientType } from 'redis';
export class RedisTestContainer {
private redis: RedisClientType | undefined;
public async init() {
this.redis = createClient({ /* config */ });
await this.redis.connect();
return this.redis;
}
public async stop() {
await this.redis?.stop();
}
}
It seems that type checking RedisClientType is taking 2.7s locally, most likely taking up a bunch of memory as it does so. From the output it seems the culprit is somewhere in multi-command.d.ts.
Replacing RedisClientType with { connect: () => Promise<unknown>; quit: () => Promise<unknown> } fixes the issue for us, since those are the only two methods we use anyway.
This fixes the issue for us, as running NODE_OPTIONS="--max-old-space-size=2048" pnpm tsc --noEmit -p tsconfig.test.json now finishes without errors. Our CI also no longer runs out of memory.
Node.js Version
22.14.0
Redis Server Version
Node Redis Version
5.1.0
Platform
MacOS, Linux
Logs
- 主要言語
- TypeScript
- スター
- 17.6k
- フォーク
- 2k
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 62
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
redis/node-redis のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
redis/node-redis#3664 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
After a MOVING handoff, a client never becomes ready again on reconnect対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
redis/node-redis#3705 ·
メンテナーはふだん 1 日以内に返信
-
accepted Bug
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
redis/node-redis#3674 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Support Uint8Array values for zero-copy transfer to worker_threads対応中かも @umeshmore45 が 286 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
redis/node-redis#3106 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
redis/node-redis#2855 · コメント 4 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
redis/node-redis の issue をすべて見る
似ている issue
-
agent/guide documentation help wanted stage/010-actionable
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
kubestellar/console-marketplace#1101 ·
メンテナーはふだん 1 日以内に返信
-
Java Edition Tests
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
JSPrismarine/JSPrismarine#4178 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
totec448-spec/chat-on-steroids#2394 ·
メンテナーはふだん 1 日以内に返信
-
github_actions
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
StellarHyperion/stellarhyperion-backend#499 ·
メンテナーはふだん 1 日以内に返信