microsoft / microsoft/TypeScript

Performance regression for declaration emit of an oversized inferred type

ใ‚ชใƒผใƒ—ใƒณ
#63,966 ใ‚ณใƒกใƒณใƒˆ 3 ไปถ ใƒชใ‚ขใ‚ฏใ‚ทใƒงใƒณ 10 ไปถ ๆ‹…ๅฝ“่€… 0 ๅ GitHub ใง่ฆ‹ใ‚‹

ใพใ ่ชฐใ‚‚็€ๆ‰‹ใ—ใฆใ„ใพใ›ใ‚“ใ€‚

Possible Improvement
ไธป่ฆ่จ€่ชž
Go
ใ‚นใ‚ฟใƒผ
111k
ใƒ•ใ‚ฉใƒผใ‚ฏ
14.3k
ๅนณๅ‡ใƒžใƒผใ‚ธ
2ๆ—ฅ 4ๆ™‚้–“
ใƒžใƒผใ‚ธๆธˆใฟ PR๏ผˆ30ๆ—ฅ๏ผ‰
132

่ชฌๆ˜Ž

๐Ÿ”Ž Search Terms

TS7056 memory, declaration emit OOM, "inferred type of this node exceeds the maximum length", DeepCloneNode serializedTypes, NodeBuilder declaration emit memory, typescript-go TS7056 RSS

๐Ÿ•— Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about declaration emit and large inferred types
  • Reproduced on 7.1.0-dev (main, ./built/local/tsc) vs TypeScript 6.0.3 (./node_modules/typescript/bin/tsc). Both report the same TS7056 and emit no .d.ts. The Go compiler uses ~6ร— the memory and is 5.8x slower.
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ version              โ”‚ peak RSS โ”‚ wall   โ”‚ result           โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 5.9.3                โ”‚ 0.51 GB  โ”‚ 0.97 s โ”‚ TS7056, no .d.ts โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 6.0.3                โ”‚ 0.41 GB  โ”‚ 0.66 s โ”‚ TS7056, no .d.ts โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 7.0.0-dev.20260707.2 โ”‚ 2.38 GB  โ”‚ 3.68 s โ”‚ TS7056, no .d.ts โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 7.0.1-rc             โ”‚ 2.25 GB  โ”‚ 3.51 s โ”‚ TS7056, no .d.ts โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ 7.0.2                โ”‚ 2.25 GB  โ”‚ 3.49 s โ”‚ TS7056, no .d.ts โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ main 7.1.0-dev       โ”‚ 2.42 GB  โ”‚ 3.41 s โ”‚ TS7056, no .d.ts โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โฏ Playground Link

N/A

๐Ÿ’ป Code
let x0 = { v: 1 };
let x1 = { a: x0, b: x0, c: x0 };
let x2 = { a: x1, b: x1, c: x1 };
let x3 = { a: x2, b: x2, c: x2 };
let x4 = { a: x3, b: x3, c: x3 };
let x5 = { a: x4, b: x4, c: x4 };
let x6 = { a: x5, b: x5, c: x5 };
let x7 = { a: x6, b: x6, c: x6 };
let x8 = { a: x7, b: x7, c: x7 };
let x9 = { a: x8, b: x8, c: x8 };
let x10 = { a: x9, b: x9, c: x9 };
let x11 = { a: x10, b: x10, c: x10 };
let x12 = { a: x11, b: x11, c: x11 };
let x13 = { a: x12, b: x12, c: x12 };
export const y = x13;
/usr/bin/time -l tsc --declaration repro.ts
๐Ÿ™ Actual behavior

Both compilers:

repro.ts(15,14): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Measured on macOS with /usr/bin/time -l:

compiler peak RSS wall
Go tsc 7.1.0-dev 2.48 GB 3.5 s
JS tsc 6.0.3 0.41 GB 0.6 s

In a limited environment, or with a larger repro, this will cause the process to OOM.

๐Ÿ™‚ Expected behavior

Go tsc should report the same TS7056 error without using extra memory and being slower.

Additional information about the issue

Disclosure: This memory issue was found with a differential memory harness (Go tsc vs JS tsc 6.0.3) and AI assistance (Kimi K3). Verified by hand against TypeScript 7.1.0-dev (main) and TypeScript 6.0.3.

ใ‚ณใƒณใƒˆใƒชใƒ“ใƒฅใƒผใ‚ทใƒงใƒณใ‚ฌใ‚คใƒ‰

ใ‚ณใƒณใƒˆใƒชใƒ“ใƒฅใƒผใ‚ทใƒงใƒณใ‚ฌใ‚คใƒ‰ใ‚’้–‹ใ

ใฏใ˜ใ‚ใฎไธ€ๆญฉ

  1. issue ใ‚’ๆœ€ๅพŒใพใง่ชญใฟใ€ๆฌกใซใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆใฎใ‚ณใƒณใƒˆใƒชใƒ“ใƒฅใƒผใ‚ทใƒงใƒณใ‚ฌใ‚คใƒ‰ใ‚’่ชญใฟใพใ™ใ€‚
  2. ็€ๆ‰‹ใ™ใ‚‹ใ“ใจใ‚’ issue ใซใ‚ณใƒกใƒณใƒˆใ—ใพใ™ โ€” ไบŒไบบใŒๅŒใ˜ไฝœๆฅญใ‚’ใ™ใ‚‹ใฎใ‚’้˜ฒใ’ใพใ™ใ€‚
  3. ใƒชใƒใ‚ธใƒˆใƒชใ‚’ใƒ•ใ‚ฉใƒผใ‚ฏใ—ใ€ใƒ–ใƒฉใƒณใƒใ‚’ๅˆ‡ใฃใฆๅค‰ๆ›ดใ—ใพใ™ใ€‚
  4. issue ็•ชๅทใ‚’ๅ‚็…งใ—ใŸใƒ—ใƒซใƒชใ‚ฏใ‚จใ‚นใƒˆใ‚’้€ใ‚Šใพใ™ใ€‚

่ชฟๆŸปใฎๆ–นๅ‘ๆ€ง

ใพใšใ€ๆไพ›ใ•ใ‚ŒใŸ repro.ts ใ‚’ declaration emit ใงๅฎŸ่กŒใ—ใ€็คบใ•ใ‚Œใฆใ„ใ‚‹ time ใ‚ณใƒžใƒณใƒ‰ใ‚’ไฝฟใฃใฆ Go tsc ใจ JavaScript ใ‚ณใƒณใƒ‘ใ‚คใƒฉใƒผใ‚’ๆฏ”่ผƒใ—ใพใ™ใ€‚ๆฌกใซใ€NodeBuilderใ€serializedTypesใ€DeepCloneNode ๅ‘จ่พบใฎ declaration-emit ใƒ‘ใ‚นใ‚’่ชฟในใพใ™ใ€‚Go ใ‚ณใƒณใƒ‘ใ‚คใƒฉใƒผใŒๅผ•ใ็ถšใ TS7056 ใ‚’ๅ ฑๅ‘Šใ—ใคใคใ€ๅ ฑๅ‘Šใ•ใ‚Œใฆใ„ใ‚‹่ฟฝๅŠ ใฎใƒกใƒขใƒชไฝฟ็”จ้‡ใจ้€ŸๅบฆไฝŽไธ‹ใ‚’ๅ›ž้ฟใงใใ‚ŒใฐๅฎŒไบ†ใงใ™ใ€‚

็ดขๅผ•ใƒขใƒ‡ใƒซใŒ issue ใฎๆœฌๆ–‡ใ‹ใ‚‰ๆ›ธใ„ใŸใ‚‚ใฎใงใ™ใ€‚

่ฉ•ไพก

ๆŠ€่ก“ใ‚นใ‚ฟใƒƒใ‚ฏ
go, typescript
้ ˜ๅŸŸ
compilers, performance
issue ใฎ็จฎ้กž
ใƒใ‚ฐ
้›ฃๆ˜“ๅบฆ
4/5
่ฆ‹็ฉใ‚‚ใ‚Šๆ™‚้–“
3ใ€œ5ๆ—ฅ
ๆดป็™บใ•
ๆดป็™บ
ๆ˜Ž็žญใ•
ใŠใŠใ‚€ใญๆ˜Ž็ขบ
ๅˆๅฟƒ่€…ใธใฎใ‚„ใ•ใ—ใ•
48/100

ๆ–ฐใ—ใ„ issue ใ‚’ใƒกใƒผใƒซใงๅ—ใ‘ๅ–ใ‚‹

ๅˆๅฟƒ่€…ๅ‘ใ‘ใฎ GitHub issue ใ‚’็Ÿญใใพใจใ‚ใŸใƒ€ใ‚คใ‚ธใ‚งใ‚นใƒˆใ€‚