Conversation

ahejlsberg

In #45025 we increased the type instantiation depth limit from 50 to 500. We've subsequently seen multiple examples of stack overflows occurring during compilation of programs containing non-terminating types, particularly when the compiler is used in browser hosted environments (where, apparently, in some cases the call stack limit is lower than in Node.js). It is clear that 500 is too high of a limit, so in this PR we lower the maximum to 100.

There are legitimate cases where evaluation of recursive conditional types needs more than 100 iterations to complete. For that reason, this PR implements tail recursive evaluation of conditional types. Specifically, when a conditional type ends in another (or, through recursion, another instantiation of the same) conditional type, the compiler now performs type resolution in a loop that consumes no extra call stack. We permit evaluation of such types to loop 1000 times before we consider the type non-terminating and issue an error.

The following conditional type is tail recursive:

type Trim<S extends string> =
    S extends ` ${infer T}` ? Trim<T> :
    S extends `${infer T} ` ? Trim<T> :
    S;

Previously, resolution of instantiations of this type would error for string literals containing more than 25 blanks. We now permit strings with up to 1000 blanks.

Conditional types that aren't tail recursive generally can be written in a tail recursive form by introducing an "accumulator". For example, this type, which extracts a union of the characters in a string, isn't tail recursive (because it recurs through a union type)

type GetChars<S> =
    S extends `${infer Char}${infer Rest}` ? Char | GetChars<Rest> : never;

but this rewritten form is

type GetChars<S> = GetCharsRec<S, never>;
type GetCharsRec<S, Acc> =
    S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;

Some additional examples of tail recursive conditional types:

type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
type ReverseRec<T, Acc extends unknown[]> =
    T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;

type T1 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;

type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
type TupleOfRec<T, N extends number, Acc extends unknown[]> =
    Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;

type T2 = TupleOf<any, 200>;

The examples above previously would error in "Type instantiation is excessively deep and possibly infinite", but now succeed.

@typescript-bottypescript-bot added Author: Team For Uncommitted BugPR for untriaged, rejected, closed or missing buglabels Sep 3, 2021
@ahejlsbergahejlsberg added this to the TypeScript 4.5.0 milestone Sep 3, 2021
@ahejlsberg

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this

@typescript-bot

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 093f76a. You can monitor the build here.

@typescript-bot

Heya @ahejlsberg, I've started to run the extended test suite on this PR at 093f76a. You can monitor the build here.

@typescript-bot

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 093f76a. You can monitor the build here.

@typescript-bot

Heya @ahejlsberg, I've started to run the perf test suite on this PR at 093f76a. You can monitor the build here.

Update: The results are in!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if we could kinda automatically do the "extract to an accumulator" thing you suggest in the OP, so people didn't need to write their conditionals with such structure in mind; but this seems good.

@typescript-bot

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@typescript-bot

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..45711

Metricmain45711DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used351,611k (± 0.03%)351,552k (± 0.02%)-59k (- 0.02%)351,375k351,666k
Parse Time1.91s (± 0.30%)1.90s (± 0.49%)-0.00s (- 0.26%)1.88s1.92s
Bind Time0.85s (± 0.40%)0.85s (± 0.70%)+0.00s (+ 0.23%)0.84s0.87s
Check Time5.39s (± 0.41%)5.40s (± 0.32%)+0.01s (+ 0.15%)5.36s5.43s
Emit Time5.83s (± 0.42%)5.84s (± 0.45%)+0.01s (+ 0.17%)5.79s5.91s
Total Time13.97s (± 0.25%)13.99s (± 0.27%)+0.02s (+ 0.11%)13.93s14.10s
Compiler-Unions - node (v10.16.3, x64)
Memory used203,474k (± 0.03%)203,450k (± 0.03%)-24k (- 0.01%)203,353k203,620k
Parse Time0.78s (± 0.85%)0.78s (± 0.87%)+0.00s (+ 0.51%)0.77s0.80s
Bind Time0.52s (± 1.13%)0.52s (± 1.28%)-0.00s (- 0.19%)0.51s0.54s
Check Time7.82s (± 0.42%)7.80s (± 0.42%)-0.02s (- 0.26%)7.75s7.91s
Emit Time2.44s (± 0.51%)2.43s (± 1.06%)-0.01s (- 0.25%)2.40s2.53s
Total Time11.56s (± 0.42%)11.54s (± 0.39%)-0.02s (- 0.15%)11.47s11.65s
Monaco - node (v10.16.3, x64)
Memory used340,659k (± 0.02%)340,634k (± 0.02%)-25k (- 0.01%)340,472k340,811k
Parse Time1.45s (± 0.69%)1.45s (± 0.67%)+0.00s (+ 0.07%)1.43s1.47s
Bind Time0.75s (± 0.87%)0.75s (± 0.40%)0.00s ( 0.00%)0.74s0.75s
Check Time5.44s (± 0.37%)5.40s (± 0.45%)-0.04s (- 0.68%)5.36s5.48s
Emit Time3.17s (± 0.78%)3.15s (± 0.58%)-0.02s (- 0.63%)3.11s3.18s
Total Time10.80s (± 0.32%)10.75s (± 0.34%)-0.05s (- 0.50%)10.67s10.82s
TFS - node (v10.16.3, x64)
Memory used304,028k (± 0.01%)304,024k (± 0.03%)-4k (- 0.00%)303,780k304,176k
Parse Time1.18s (± 0.52%)1.19s (± 0.57%)+0.01s (+ 0.59%)1.18s1.21s
Bind Time0.72s (± 0.95%)0.71s (± 1.06%)-0.00s (- 0.14%)0.70s0.73s
Check Time4.92s (± 0.56%)4.94s (± 0.62%)+0.03s (+ 0.53%)4.86s4.99s
Emit Time3.31s (± 1.05%)3.37s (± 1.96%)+0.06s (+ 1.72%)3.25s3.52s
Total Time10.12s (± 0.45%)10.21s (± 0.71%)+0.09s (+ 0.86%)10.08s10.40s
material-ui - node (v10.16.3, x64)
Memory used469,942k (± 0.01%)469,793k (± 0.01%)-149k (- 0.03%)469,715k469,940k
Parse Time1.73s (± 0.40%)1.73s (± 0.43%)+0.01s (+ 0.46%)1.72s1.75s
Bind Time0.66s (± 0.55%)0.67s (± 0.51%)+0.01s (+ 1.36%)0.67s0.68s
Check Time14.15s (± 0.27%)14.35s (± 0.65%)+0.20s (+ 1.43%)14.16s14.60s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.54s (± 0.24%)16.76s (± 0.58%)+0.22s (+ 1.31%)16.56s17.01s
Angular - node (v12.1.0, x64)
Memory used329,584k (± 0.03%)329,534k (± 0.02%)-49k (- 0.01%)329,365k329,668k
Parse Time1.88s (± 0.62%)1.88s (± 0.48%)-0.00s (- 0.21%)1.85s1.89s
Bind Time0.83s (± 0.44%)0.84s (± 0.80%)+0.00s (+ 0.24%)0.82s0.85s
Check Time5.22s (± 0.52%)5.22s (± 0.39%)+0.01s (+ 0.10%)5.19s5.28s
Emit Time6.05s (± 0.49%)6.13s (± 1.46%)+0.08s (+ 1.32%)6.04s6.47s
Total Time13.98s (± 0.31%)14.07s (± 0.71%)+0.08s (+ 0.59%)13.94s14.41s
Compiler-Unions - node (v12.1.0, x64)
Memory used191,013k (± 0.02%)190,985k (± 0.03%)-28k (- 0.01%)190,894k191,166k
Parse Time0.78s (± 0.83%)0.78s (± 0.88%)-0.01s (- 0.77%)0.76s0.79s
Bind Time0.52s (± 1.13%)0.53s (± 1.09%)+0.01s (+ 1.15%)0.52s0.54s
Check Time7.37s (± 0.58%)7.39s (± 0.72%)+0.02s (+ 0.22%)7.31s7.50s
Emit Time2.47s (± 1.18%)2.45s (± 0.78%)-0.02s (- 0.61%)2.42s2.51s
Total Time11.15s (± 0.49%)11.15s (± 0.57%)0.00s ( 0.00%)11.04s11.28s
Monaco - node (v12.1.0, x64)
Memory used323,734k (± 0.01%)323,779k (± 0.02%)+45k (+ 0.01%)323,576k323,859k
Parse Time1.43s (± 0.51%)1.43s (± 0.85%)+0.00s (+ 0.21%)1.41s1.46s
Bind Time0.72s (± 0.47%)0.73s (± 0.92%)+0.00s (+ 0.55%)0.71s0.74s
Check Time5.26s (± 0.43%)5.28s (± 0.37%)+0.03s (+ 0.49%)5.23s5.31s
Emit Time3.19s (± 0.67%)3.19s (± 0.78%)-0.00s (- 0.06%)3.15s3.25s
Total Time10.60s (± 0.35%)10.63s (± 0.30%)+0.03s (+ 0.30%)10.54s10.69s
TFS - node (v12.1.0, x64)
Memory used288,714k (± 0.02%)288,785k (± 0.02%)+71k (+ 0.02%)288,664k288,910k
Parse Time1.20s (± 0.77%)1.21s (± 0.93%)+0.01s (+ 0.75%)1.19s1.24s
Bind Time0.70s (± 0.71%)0.70s (± 0.97%)+0.01s (+ 1.29%)0.69s0.72s
Check Time4.83s (± 0.41%)4.87s (± 0.53%)+0.04s (+ 0.81%)4.82s4.92s
Emit Time3.37s (± 0.55%)3.40s (± 0.83%)+0.03s (+ 0.77%)3.34s3.48s
Total Time10.10s (± 0.32%)10.18s (± 0.55%)+0.08s (+ 0.82%)10.05s10.34s
material-ui - node (v12.1.0, x64)
Memory used448,462k (± 0.07%)448,419k (± 0.05%)-43k (- 0.01%)447,608k448,684k
Parse Time1.72s (± 0.47%)1.73s (± 0.50%)+0.00s (+ 0.29%)1.71s1.75s
Bind Time0.65s (± 0.86%)0.65s (± 0.91%)+0.01s (+ 0.93%)0.64s0.67s
Check Time12.78s (± 0.53%)12.97s (± 0.89%)+0.19s (+ 1.50%)12.76s13.24s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.15s (± 0.46%)15.36s (± 0.78%)+0.20s (+ 1.34%)15.16s15.63s
Angular - node (v14.15.1, x64)
Memory used328,115k (± 0.01%)328,111k (± 0.01%)-4k (- 0.00%)328,022k328,206k
Parse Time1.91s (± 0.70%)1.90s (± 0.52%)-0.01s (- 0.37%)1.88s1.92s
Bind Time0.88s (± 1.13%)0.88s (± 0.41%)+0.00s (+ 0.45%)0.88s0.89s
Check Time5.29s (± 0.46%)5.28s (± 0.47%)-0.01s (- 0.13%)5.21s5.33s
Emit Time6.22s (± 0.87%)6.22s (± 0.78%)-0.01s (- 0.10%)6.12s6.30s
Total Time14.30s (± 0.55%)14.29s (± 0.49%)-0.02s (- 0.11%)14.11s14.39s
Compiler-Unions - node (v14.15.1, x64)
Memory used192,165k (± 0.48%)192,487k (± 0.38%)+321k (+ 0.17%)189,506k192,910k
Parse Time0.81s (± 0.76%)0.81s (± 0.58%)+0.00s (+ 0.12%)0.80s0.82s
Bind Time0.55s (± 1.08%)0.56s (± 0.53%)+0.00s (+ 0.54%)0.55s0.56s
Check Time7.50s (± 0.50%)7.54s (± 0.71%)+0.04s (+ 0.52%)7.42s7.65s
Emit Time2.45s (± 0.58%)2.46s (± 0.56%)+0.01s (+ 0.45%)2.43s2.49s
Total Time11.31s (± 0.44%)11.37s (± 0.50%)+0.06s (+ 0.51%)11.26s11.52s
Monaco - node (v14.15.1, x64)
Memory used322,544k (± 0.00%)322,548k (± 0.01%)+4k (+ 0.00%)322,489k322,578k
Parse Time1.49s (± 0.98%)1.49s (± 0.61%)+0.00s (+ 0.27%)1.47s1.51s
Bind Time0.75s (± 0.40%)0.76s (± 0.66%)+0.00s (+ 0.40%)0.75s0.77s
Check Time5.21s (± 0.61%)5.24s (± 0.27%)+0.03s (+ 0.58%)5.22s5.28s
Emit Time3.22s (± 0.63%)3.22s (± 0.65%)0.00s ( 0.00%)3.16s3.26s
Total Time10.67s (± 0.46%)10.71s (± 0.27%)+0.04s (+ 0.34%)10.61s10.75s
TFS - node (v14.15.1, x64)
Memory used287,699k (± 0.01%)287,695k (± 0.00%)-5k (- 0.00%)287,669k287,707k
Parse Time1.26s (± 1.13%)1.25s (± 2.11%)-0.01s (- 0.48%)1.21s1.34s
Bind Time0.72s (± 0.80%)0.76s (± 4.49%)+0.04s (+ 5.28%)0.71s0.83s
Check Time4.86s (± 0.54%)4.87s (± 0.68%)+0.01s (+ 0.14%)4.79s4.92s
Emit Time3.46s (± 1.01%)3.46s (± 0.88%)-0.00s (- 0.14%)3.40s3.53s
Total Time10.30s (± 0.40%)10.34s (± 0.60%)+0.03s (+ 0.33%)10.20s10.44s
material-ui - node (v14.15.1, x64)
Memory used447,023k (± 0.00%)446,915k (± 0.01%)-108k (- 0.02%)446,870k446,976k
Parse Time1.76s (± 0.47%)1.77s (± 0.62%)+0.02s (+ 0.97%)1.75s1.80s
Bind Time0.68s (± 0.87%)0.69s (± 0.94%)+0.01s (+ 1.02%)0.68s0.71s
Check Time12.90s (± 0.53%)13.19s (± 0.49%)+0.29s (+ 2.27%)13.00s13.34s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.34s (± 0.50%)15.66s (± 0.42%)+0.32s (+ 2.09%)15.47s15.78s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory9 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
BenchmarkNameIterations
Current4571110
Baselinemain10

Developer Information:

Download Benchmark

@DanielRosenwasser

I can't tell how much of this in the noise, but the check time on material-ui does seem like it's taken a hit across all versions.

@ahejlsberg

@typescript-bot perf test this

@typescript-bot

Heya @ahejlsberg, I've started to run the perf test suite on this PR at a4224d6. You can monitor the build here.

Update: The results are in!

@typescript-bot

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..45711

Metricmain45711DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used351,498k (± 0.02%)351,568k (± 0.02%)+70k (+ 0.02%)351,360k351,643k
Parse Time1.90s (± 0.34%)1.91s (± 0.68%)+0.01s (+ 0.63%)1.89s1.94s
Bind Time0.85s (± 0.76%)0.86s (± 0.69%)+0.01s (+ 0.94%)0.85s0.87s
Check Time5.40s (± 0.45%)5.41s (± 0.37%)+0.01s (+ 0.24%)5.36s5.47s
Emit Time5.83s (± 0.29%)5.86s (± 0.64%)+0.03s (+ 0.55%)5.77s5.95s
Total Time13.97s (± 0.26%)14.04s (± 0.38%)+0.07s (+ 0.48%)13.88s14.14s
Compiler-Unions - node (v10.16.3, x64)
Memory used203,519k (± 0.04%)203,445k (± 0.03%)-74k (- 0.04%)203,329k203,611k
Parse Time0.78s (± 0.85%)0.79s (± 0.89%)+0.01s (+ 1.15%)0.77s0.80s
Bind Time0.52s (± 1.43%)0.52s (± 1.66%)-0.00s (- 0.19%)0.51s0.54s
Check Time7.84s (± 0.50%)7.89s (± 0.64%)+0.05s (+ 0.66%)7.76s7.99s
Emit Time2.44s (± 0.70%)2.46s (± 0.74%)+0.02s (+ 0.61%)2.42s2.49s
Total Time11.58s (± 0.37%)11.65s (± 0.54%)+0.07s (+ 0.60%)11.51s11.77s
Monaco - node (v10.16.3, x64)
Memory used340,627k (± 0.03%)340,619k (± 0.02%)-9k (- 0.00%)340,464k340,827k
Parse Time1.45s (± 0.90%)1.46s (± 0.46%)+0.01s (+ 0.76%)1.44s1.47s
Bind Time0.75s (± 1.07%)0.75s (± 0.60%)0.00s ( 0.00%)0.74s0.76s
Check Time5.44s (± 0.60%)5.41s (± 0.72%)-0.03s (- 0.50%)5.31s5.49s
Emit Time3.16s (± 0.86%)3.16s (± 1.04%)+0.01s (+ 0.25%)3.11s3.26s
Total Time10.79s (± 0.44%)10.78s (± 0.29%)-0.01s (- 0.05%)10.71s10.86s
TFS - node (v10.16.3, x64)
Memory used303,979k (± 0.03%)304,033k (± 0.02%)+55k (+ 0.02%)303,923k304,196k
Parse Time1.18s (± 0.59%)1.18s (± 0.31%)+0.00s (+ 0.25%)1.18s1.19s
Bind Time0.71s (± 0.52%)0.71s (± 0.69%)-0.00s (- 0.14%)0.71s0.73s
Check Time4.92s (± 0.65%)4.93s (± 0.43%)+0.01s (+ 0.20%)4.89s4.97s
Emit Time3.32s (± 1.36%)3.32s (± 1.45%)+0.00s (+ 0.06%)3.22s3.43s
Total Time10.13s (± 0.60%)10.15s (± 0.56%)+0.01s (+ 0.13%)10.00s10.28s
material-ui - node (v10.16.3, x64)
Memory used469,920k (± 0.02%)469,714k (± 0.01%)-207k (- 0.04%)469,641k469,788k
Parse Time1.73s (± 0.70%)1.74s (± 0.61%)+0.01s (+ 0.35%)1.72s1.76s
Bind Time0.66s (± 0.45%)0.67s (± 0.67%)+0.01s (+ 0.91%)0.66s0.68s
Check Time14.19s (± 0.63%)14.44s (± 0.92%)+0.25s (+ 1.76%)14.17s14.71s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.59s (± 0.55%)16.85s (± 0.85%)+0.26s (+ 1.56%)16.57s17.15s
Angular - node (v12.1.0, x64)
Memory used329,562k (± 0.02%)329,438k (± 0.08%)-124k (- 0.04%)328,468k329,679k
Parse Time1.89s (± 0.82%)1.89s (± 0.77%)+0.00s (+ 0.05%)1.86s1.92s
Bind Time0.84s (± 0.95%)0.84s (± 0.79%)+0.00s (+ 0.12%)0.83s0.86s
Check Time5.25s (± 0.64%)5.28s (± 0.93%)+0.03s (+ 0.50%)5.14s5.34s
Emit Time6.08s (± 0.55%)6.11s (± 0.53%)+0.03s (+ 0.54%)6.02s6.17s
Total Time14.06s (± 0.43%)14.12s (± 0.57%)+0.06s (+ 0.43%)13.92s14.24s
Compiler-Unions - node (v12.1.0, x64)
Memory used190,701k (± 0.32%)190,839k (± 0.13%)+137k (+ 0.07%)190,261k191,234k
Parse Time0.78s (± 0.77%)0.78s (± 0.85%)+0.00s (+ 0.52%)0.77s0.80s
Bind Time0.54s (± 0.92%)0.53s (± 0.84%)-0.00s (- 0.75%)0.53s0.55s
Check Time7.41s (± 0.69%)7.42s (± 0.79%)+0.01s (+ 0.18%)7.26s7.54s
Emit Time2.46s (± 1.08%)2.47s (± 0.92%)+0.01s (+ 0.61%)2.43s2.53s
Total Time11.17s (± 0.46%)11.20s (± 0.59%)+0.03s (+ 0.26%)11.02s11.35s
Monaco - node (v12.1.0, x64)
Memory used323,777k (± 0.02%)323,810k (± 0.02%)+33k (+ 0.01%)323,637k323,961k
Parse Time1.43s (± 0.61%)1.44s (± 0.77%)+0.01s (+ 0.63%)1.42s1.46s
Bind Time0.73s (± 0.50%)0.73s (± 0.41%)+0.01s (+ 0.83%)0.73s0.74s
Check Time5.30s (± 0.34%)5.32s (± 0.75%)+0.02s (+ 0.38%)5.23s5.43s
Emit Time3.19s (± 0.71%)3.19s (± 0.63%)-0.01s (- 0.22%)3.15s3.24s
Total Time10.65s (± 0.16%)10.68s (± 0.60%)+0.02s (+ 0.23%)10.52s10.83s
TFS - node (v12.1.0, x64)
Memory used288,768k (± 0.02%)288,762k (± 0.02%)-6k (- 0.00%)288,621k288,915k
Parse Time1.21s (± 0.72%)1.22s (± 0.83%)+0.01s (+ 0.66%)1.20s1.24s
Bind Time0.71s (± 1.36%)0.70s (± 1.18%)-0.00s (- 0.56%)0.69s0.72s
Check Time4.87s (± 0.49%)4.87s (± 0.29%)+0.01s (+ 0.12%)4.85s4.90s
Emit Time3.39s (± 1.13%)3.38s (± 0.61%)-0.01s (- 0.32%)3.32s3.42s
Total Time10.17s (± 0.63%)10.17s (± 0.25%)+0.00s (+ 0.04%)10.10s10.23s
material-ui - node (v12.1.0, x64)
Memory used448,584k (± 0.02%)448,412k (± 0.06%)-172k (- 0.04%)447,378k448,617k
Parse Time1.72s (± 0.62%)1.73s (± 0.64%)+0.01s (+ 0.64%)1.70s1.75s
Bind Time0.65s (± 0.90%)0.65s (± 1.02%)+0.01s (+ 0.93%)0.63s0.66s
Check Time12.85s (± 0.43%)13.00s (± 0.75%)+0.15s (+ 1.14%)12.79s13.19s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.22s (± 0.32%)15.38s (± 0.66%)+0.16s (+ 1.08%)15.15s15.59s
Angular - node (v14.15.1, x64)
Memory used328,088k (± 0.01%)328,103k (± 0.01%)+15k (+ 0.00%)328,050k328,149k
Parse Time1.90s (± 0.73%)1.91s (± 0.64%)+0.01s (+ 0.63%)1.89s1.94s
Bind Time0.88s (± 0.51%)0.88s (± 0.93%)+0.00s (+ 0.11%)0.87s0.91s
Check Time5.30s (± 0.76%)5.32s (± 0.67%)+0.02s (+ 0.32%)5.24s5.43s
Emit Time6.22s (± 0.72%)6.18s (± 0.70%)-0.04s (- 0.71%)6.11s6.31s
Total Time14.30s (± 0.51%)14.29s (± 0.54%)-0.01s (- 0.09%)14.18s14.55s
Compiler-Unions - node (v14.15.1, x64)
Memory used191,742k (± 0.55%)192,190k (± 0.49%)+448k (+ 0.23%)189,614k192,907k
Parse Time0.81s (± 0.92%)0.81s (± 0.45%)-0.00s (- 0.12%)0.80s0.81s
Bind Time0.56s (± 0.85%)0.56s (± 0.99%)+0.01s (+ 0.90%)0.55s0.58s
Check Time7.55s (± 0.61%)7.55s (± 0.52%)-0.00s (- 0.03%)7.49s7.68s
Emit Time2.48s (± 1.01%)2.46s (± 0.82%)-0.02s (- 0.73%)2.41s2.49s
Total Time11.39s (± 0.32%)11.37s (± 0.48%)-0.02s (- 0.16%)11.27s11.54s
Monaco - node (v14.15.1, x64)
Memory used322,540k (± 0.00%)322,541k (± 0.00%)+1k (+ 0.00%)322,511k322,563k
Parse Time1.48s (± 0.68%)1.49s (± 0.67%)+0.00s (+ 0.20%)1.47s1.51s
Bind Time0.76s (± 0.66%)0.76s (± 0.99%)+0.00s (+ 0.26%)0.75s0.78s
Check Time5.23s (± 0.43%)5.23s (± 0.51%)+0.01s (+ 0.13%)5.19s5.29s
Emit Time3.21s (± 0.69%)3.24s (± 1.03%)+0.02s (+ 0.72%)3.18s3.31s
Total Time10.68s (± 0.34%)10.72s (± 0.42%)+0.03s (+ 0.32%)10.63s10.82s
TFS - node (v14.15.1, x64)
Memory used287,700k (± 0.01%)287,713k (± 0.01%)+13k (+ 0.00%)287,663k287,761k
Parse Time1.26s (± 2.81%)1.26s (± 2.13%)+0.00s (+ 0.24%)1.21s1.33s
Bind Time0.73s (± 1.27%)0.73s (± 1.11%)+0.00s (+ 0.27%)0.72s0.75s
Check Time4.87s (± 0.35%)4.91s (± 0.46%)+0.04s (+ 0.76%)4.84s4.97s
Emit Time3.47s (± 0.77%)3.49s (± 0.84%)+0.02s (+ 0.72%)3.43s3.57s
Total Time10.32s (± 0.42%)10.38s (± 0.43%)+0.07s (+ 0.65%)10.27s10.46s
material-ui - node (v14.15.1, x64)
Memory used447,030k (± 0.01%)446,950k (± 0.00%)-80k (- 0.02%)446,922k446,990k
Parse Time1.76s (± 0.48%)1.77s (± 0.33%)+0.01s (+ 0.63%)1.76s1.78s
Bind Time0.69s (± 0.58%)0.69s (± 0.49%)+0.00s (+ 0.29%)0.69s0.70s
Check Time13.02s (± 0.60%)13.13s (± 0.71%)+0.12s (+ 0.88%)12.87s13.26s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.47s (± 0.50%)15.59s (± 0.59%)+0.13s (+ 0.83%)15.33s15.72s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory9 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
BenchmarkNameIterations
Current4571110
Baselinemain10

Developer Information:

Download Benchmark

@ahejlsberg

Changed the tail recursion logic to bypass caching since it is effectively just computing temporary results. There's still a slight slowdown in material-ui (<1%), but generally I think not caching in the tail recursion loop is the best approach.

@ahejlsbergahejlsberg merged commit b9eeb74 into main Sep 8, 2021
@ahejlsbergahejlsberg deleted the tailRecursiveConditionals branch September 8, 2021 22:42
@mgreenw

@ahejlsberg Thanks for this work! Using 4.4.3, I just hit the instantiationDepth === 50 limit (literally just 50, nothing above that) on a project I am working on.

Because it is possible / even likely to hit this depth limit of 50 with tuple types and template literal types in 4.4, I'm wondering if it would be possible to backport the instantiationDepth === 100 limit to a new release of 4.4 without including this tail recursive evaluation strategy This would mitigate the issue until 4.5 is released with this new (awesome) work. Let me know if you think this would be possible / a good idea. Thanks!

MajorLift added a commit to MajorLift/type-challenges that referenced this pull request Jan 6, 2023
- TypeScript currently permits up to 1000 recursive loops.
- See: microsoft/TypeScript#45711
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Author: Team For Uncommitted BugPR for untriaged, rejected, closed or missing bug
None yet

Successfully merging this pull request may close these issues.