Skip to content

Ensure that Comparers only return -1, 0, 1 so results can be equated - #52897

Closed
Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:mainfrom
jakebailey:fix-comparer
Closed

Ensure that Comparers only return -1, 0, 1 so results can be equated#52897
Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:mainfrom
jakebailey:fix-comparer

Conversation

@jakebailey

Copy link
Copy Markdown
Member

I noticed this while working on cleaning up our (inconsistent) use of the binary search and ordered insert APIs.

The binary search API requires that you have comparisons of exactly-1 | 0 | 1, however, we had some comparers which didn't do this thanks to a hole in our type system (Playground Link).

Make it so that we consistently return only one of the three valid values, so comparers can always be used in all APIs.

I also noticed (but did not change) the fact that we use binary searches for things like import insertion with the assumption that the input is always sorted, but, I don't think this actually turns out to be the case all the time anymore?

@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test this

@typescript-bot

TypeScript Bot (typescript-bot) commented Feb 21, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the perf test suite on this PR at 2106d54. You can monitor the build here.

Update: The results are in!

@DanielRosenwasser

Copy link
Copy Markdown
Member

Does this catch any actual bugs? Should we just change the comparer type to return number, and use Comparison as a set of easily accessible constants?

@jakebailey

Copy link
Copy Markdown
MemberAuthor

Does this catch any actual bugs? Should we just change the comparer type to return number, and use Comparison as a set of easily accessible constants?

No, it doesn't, and that surprised me.

If we want to do that, the binary search API needs to change to not check equality on Comparison values. That could definitely be a good fix for this too.

@jakebailey

Jake Bailey (jakebailey) commented Feb 21, 2023

Copy link
Copy Markdown
MemberAuthor

Well, it did catch one bug; When I was working on #52891, I accidentally passed getTypeId as a Comparer, and had no idea what I had done wrong. I think that's the benefit here, but, I'm not strongly attached to it.

I think that if we had any existing bugs related to this, they'd already have been caught, because the result is pretty catastrophic.

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..52897
Metricmain52897DeltaBestWorstp-value
Angular - node (v18.10.0, x64)
Memory used359,665k (± 0.01%)359,683k (± 0.02%)~359,592k359,766kp=0.689 n=6
Parse Time3.49s (± 0.88%)3.48s (± 0.65%)~3.45s3.51sp=0.519 n=6
Bind Time1.17s (± 0.64%)1.17s (± 1.03%)~1.15s1.18sp=0.485 n=6
Check Time8.76s (± 0.26%)8.76s (± 0.34%)~8.72s8.81sp=0.732 n=6
Emit Time7.61s (± 1.18%)7.61s (± 0.63%)~7.54s7.68sp=0.686 n=6
Total Time21.02s (± 0.48%)21.02s (± 0.23%)~20.96s21.10sp=0.684 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used193,630k (± 1.48%)191,839k (± 1.55%)~189,848k195,726kp=1.000 n=6
Parse Time1.48s (± 0.66%)1.48s (± 0.28%)~1.47s1.48sp=0.930 n=6
Bind Time0.80s (± 0.69%)0.80s (± 0.69%)~0.79s0.80sp=1.000 n=6
Check Time9.45s (± 0.58%)9.46s (± 0.52%)~9.41s9.53sp=0.686 n=6
Emit Time2.81s (± 1.13%)2.81s (± 0.66%)~2.79s2.84sp=0.570 n=6
Total Time14.53s (± 0.48%)14.54s (± 0.31%)~14.48s14.60sp=0.936 n=6
Monaco - node (v18.10.0, x64)
Memory used344,051k (± 0.02%)344,045k (± 0.02%)~343,980k344,129kp=0.810 n=6
Parse Time2.62s (± 1.05%)2.63s (± 1.05%)~2.59s2.66sp=0.418 n=6
Bind Time1.05s (± 0.80%)1.04s (± 0.95%)~1.02s1.05sp=0.340 n=6
Check Time7.11s (± 0.25%)7.13s (± 0.46%)~7.08s7.17sp=0.195 n=6
Emit Time4.34s (± 1.06%)4.33s (± 0.55%)~4.29s4.36sp=0.739 n=6
Total Time15.12s (± 0.48%)15.13s (± 0.15%)~15.11s15.17sp=0.872 n=6
TFS - node (v18.10.0, x64)
Memory used300,066k (± 0.00%)300,089k (± 0.01%)~300,062k300,145kp=0.054 n=6
Parse Time2.08s (± 0.77%)2.04s (± 1.47%)~2.01s2.08sp=0.163 n=6
Bind Time1.17s (± 0.76%)1.18s (± 1.03%)~1.17s1.20sp=0.437 n=6
Check Time6.57s (± 0.22%)6.58s (± 0.28%)~6.55s6.60sp=0.808 n=6
Emit Time3.92s (± 0.90%)3.90s (± 0.42%)~3.88s3.92sp=0.806 n=6
Total Time13.74s (± 0.38%)13.70s (± 0.33%)~13.62s13.75sp=0.469 n=6
material-ui - node (v18.10.0, x64)
Memory used476,437k (± 0.01%)476,400k (± 0.01%)~476,373k476,453kp=0.066 n=6
Parse Time3.15s (± 0.52%)3.16s (± 0.24%)~3.15s3.17sp=0.216 n=6
Bind Time0.97s (± 1.01%)0.97s (± 0.78%)~0.96s0.98sp=0.652 n=6
Check Time17.30s (± 0.62%)17.23s (± 0.74%)~17.04s17.40sp=0.375 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time21.42s (± 0.57%)21.36s (± 0.61%)~21.15s21.53sp=0.575 n=6
xstate - node (v18.10.0, x64)
Memory used548,584k (± 0.02%)548,509k (± 0.03%)~548,328k548,809kp=0.298 n=6
Parse Time4.06s (± 0.55%)4.07s (± 0.40%)~4.04s4.09sp=0.332 n=6
Bind Time1.71s (± 0.61%)1.72s (± 1.35%)~1.69s1.75sp=1.000 n=6
Check Time2.83s (± 0.99%)2.82s (± 0.69%)~2.79s2.84sp=0.687 n=6
Emit Time0.08s (± 0.00%)0.08s (± 6.19%)~0.08s0.09sp=0.176 n=6
Total Time8.69s (± 0.40%)8.69s (± 0.21%)~8.66s8.71sp=0.935 n=6
Angular - node (v16.17.1, x64)
Memory used359,020k (± 0.01%)359,064k (± 0.01%)~359,010k359,124kp=0.298 n=6
Parse Time3.72s (± 0.43%)3.72s (± 0.49%)~3.69s3.73sp=0.870 n=6
Bind Time1.23s (± 0.73%)1.23s (± 0.95%)~1.22s1.25sp=0.933 n=6
Check Time9.55s (± 0.31%)9.52s (± 0.27%)~9.48s9.55sp=0.107 n=6
Emit Time8.08s (± 0.44%)8.05s (± 0.53%)~8.00s8.09sp=0.373 n=6
Total Time22.58s (± 0.27%)22.52s (± 0.18%)~22.46s22.57sp=0.127 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used191,538k (± 0.03%)191,560k (± 0.04%)~191,425k191,657kp=0.471 n=6
Parse Time1.54s (± 1.46%)1.57s (± 0.52%)~1.55s1.57sp=0.055 n=6
Bind Time0.84s (± 0.61%)0.84s (± 0.00%)~0.84s0.84sp=0.174 n=6
Check Time10.11s (± 0.47%)10.17s (± 0.27%)~10.13s10.20sp=0.064 n=6
Emit Time3.05s (± 1.01%)3.06s (± 0.81%)~3.04s3.11sp=0.627 n=6
Total Time15.54s (± 0.41%)15.63s (± 0.31%)+0.09s (+ 0.59%)15.57s15.71sp=0.030 n=6
Monaco - node (v16.17.1, x64)
Memory used343,349k (± 0.00%)343,344k (± 0.00%)~343,320k343,361kp=0.375 n=6
Parse Time2.80s (± 0.71%)2.80s (± 0.53%)~2.78s2.82sp=1.000 n=6
Bind Time1.11s (± 0.37%)1.11s (± 0.37%)~1.11s1.12sp=1.000 n=6
Check Time7.82s (± 0.36%)7.80s (± 0.20%)~7.79s7.83sp=0.145 n=6
Emit Time4.52s (± 0.73%)4.52s (± 0.83%)~4.48s4.57sp=0.809 n=6
Total Time16.25s (± 0.19%)16.23s (± 0.21%)~16.19s16.28sp=0.260 n=6
TFS - node (v16.17.1, x64)
Memory used299,418k (± 0.00%)299,414k (± 0.01%)~299,396k299,438kp=0.689 n=6
Parse Time2.20s (± 0.99%)2.19s (± 0.55%)~2.18s2.21sp=0.684 n=6
Bind Time1.25s (± 0.67%)1.26s (± 0.41%)~1.26s1.27sp=0.073 n=6
Check Time7.25s (± 0.33%)7.25s (± 0.32%)~7.23s7.28sp=0.871 n=6
Emit Time4.24s (± 0.94%)4.23s (± 0.78%)~4.20s4.29sp=0.870 n=6
Total Time14.94s (± 0.51%)14.94s (± 0.28%)~14.89s14.99sp=0.936 n=6
material-ui - node (v16.17.1, x64)
Memory used475,699k (± 0.00%)475,693k (± 0.00%)~475,652k475,713kp=0.748 n=6
Parse Time3.33s (± 0.29%)3.33s (± 0.25%)~3.32s3.34sp=0.195 n=6
Bind Time1.02s (± 0.50%)1.02s (± 0.00%)~1.02s1.02sp=0.174 n=6
Check Time18.28s (± 0.69%)18.20s (± 0.46%)~18.12s18.35sp=0.335 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time22.63s (± 0.57%)22.55s (± 0.38%)~22.46s22.70sp=0.261 n=6
xstate - node (v16.17.1, x64)
Memory used546,132k (± 0.02%)546,130k (± 0.02%)~546,018k546,277kp=0.936 n=6
Parse Time4.25s (± 0.27%)4.25s (± 0.39%)~4.23s4.28sp=0.681 n=6
Bind Time1.81s (± 0.64%)1.81s (± 0.64%)~1.80s1.83sp=1.000 n=6
Check Time3.06s (± 0.96%)3.07s (± 0.87%)~3.02s3.09sp=0.802 n=6
Emit Time0.09s (± 0.00%)0.09s (± 0.00%)~0.09s0.09sp=1.000 n=6
Total Time9.22s (± 0.42%)9.22s (± 0.37%)~9.17s9.26sp=1.000 n=6
Angular - node (v14.15.1, x64)
Memory used352,589k (± 0.01%)352,586k (± 0.01%)~352,562k352,637kp=0.810 n=6
Parse Time3.73s (± 0.26%)3.71s (± 0.33%)-0.02s (- 0.45%)3.70s3.73sp=0.027 n=6
Bind Time1.28s (± 0.70%)1.28s (± 0.59%)~1.27s1.29sp=0.798 n=6
Check Time9.84s (± 0.37%)9.84s (± 0.60%)~9.78s9.95sp=0.810 n=6
Emit Time8.42s (± 0.77%)8.35s (± 0.39%)~8.30s8.39sp=0.252 n=6
Total Time23.28s (± 0.17%)23.19s (± 0.35%)~23.11s23.33sp=0.109 n=6
Compiler-Unions - node (v14.15.1, x64)
Memory used186,673k (± 0.01%)186,684k (± 0.02%)~186,638k186,727kp=0.521 n=6
Parse Time1.58s (± 0.77%)1.58s (± 1.13%)~1.56s1.61sp=0.864 n=6
Bind Time0.86s (± 0.88%)0.86s (± 0.95%)~0.85s0.87sp=0.729 n=6
Check Time10.24s (± 0.76%)10.24s (± 0.74%)~10.16s10.33sp=0.809 n=6
Emit Time3.18s (± 0.70%)3.17s (± 1.03%)~3.13s3.22sp=0.327 n=6
Total Time15.85s (± 0.57%)15.84s (± 0.49%)~15.76s15.96sp=0.687 n=6
Monaco - node (v14.15.1, x64)
Memory used338,190k (± 0.01%)338,189k (± 0.01%)~338,162k338,212kp=0.748 n=6
Parse Time2.90s (± 0.31%)2.90s (± 0.48%)~2.88s2.91sp=0.562 n=6
Bind Time1.12s (± 0.92%)1.12s (± 0.75%)~1.10s1.12sp=0.788 n=6
Check Time8.15s (± 0.27%)8.13s (± 0.49%)~8.08s8.18sp=0.295 n=6
Emit Time4.81s (± 0.46%)4.77s (± 0.45%)-0.04s (- 0.83%)4.74s4.79sp=0.016 n=6
Total Time16.98s (± 0.20%)16.91s (± 0.32%)-0.07s (- 0.42%)16.85s16.99sp=0.037 n=6
TFS - node (v14.15.1, x64)
Memory used294,346k (± 0.00%)294,351k (± 0.00%)~294,341k294,375kp=0.748 n=6
Parse Time2.39s (± 0.62%)2.38s (± 0.82%)~2.37s2.42sp=0.459 n=6
Bind Time1.10s (± 0.99%)1.10s (± 0.89%)~1.09s1.11sp=0.859 n=6
Check Time7.53s (± 0.59%)7.54s (± 0.43%)~7.49s7.59sp=0.628 n=6
Emit Time4.65s (± 0.77%)4.62s (± 1.17%)~4.59s4.73sp=0.145 n=6
Total Time15.66s (± 0.31%)15.64s (± 0.20%)~15.61s15.70sp=0.469 n=6
material-ui - node (v14.15.1, x64)
Memory used471,240k (± 0.00%)471,233k (± 0.01%)~471,198k471,282kp=0.377 n=6
Parse Time3.49s (± 0.12%)3.49s (± 0.23%)~3.48s3.50sp=0.584 n=6
Bind Time1.04s (± 0.61%)1.04s (± 1.05%)~1.03s1.06sp=0.787 n=6
Check Time19.18s (± 0.57%)19.11s (± 0.43%)~19.03s19.25sp=0.261 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time23.72s (± 0.45%)23.65s (± 0.37%)~23.55s23.79sp=0.298 n=6
xstate - node (v14.15.1, x64)
Memory used534,515k (± 0.01%)534,473k (± 0.02%)~534,324k534,547kp=0.689 n=6
Parse Time4.60s (± 0.45%)4.59s (± 0.22%)~4.58s4.61sp=0.323 n=6
Bind Time1.73s (± 0.48%)1.72s (± 0.30%)~1.71s1.72sp=0.073 n=6
Check Time3.16s (± 0.73%)3.15s (± 0.68%)~3.12s3.18sp=0.520 n=6
Emit Time0.10s (± 4.01%)0.10s (± 0.00%)~0.10s0.10sp=0.405 n=6
Total Time9.60s (± 0.22%)9.57s (± 0.21%)~9.55s9.60sp=0.064 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.15.1, x64)
BenchmarkNameIterations
Current528976
Baselinemain6

TSServer

Comparison Report - main..52897
Metricmain52897DeltaBestWorstp-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen2,380ms (± 0.38%)2,379ms (± 0.44%)~2,367ms2,394msp=0.873 n=6
Req 2 - geterr5,350ms (± 0.42%)5,383ms (± 0.31%)+33ms (+ 0.62%)5,367ms5,406msp=0.020 n=6
Req 3 - references342ms (± 1.42%)341ms (± 1.48%)~335ms348msp=0.625 n=6
Req 4 - navto282ms (± 0.62%)283ms (± 0.58%)~280ms285msp=0.288 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo72ms (± 0.88%)72ms (± 0.57%)~71ms72msp=0.673 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen2,504ms (± 0.74%)2,504ms (± 0.75%)~2,475ms2,533msp=1.000 n=6
Req 2 - geterr4,029ms (± 0.62%)4,039ms (± 0.82%)~4,007ms4,073msp=0.630 n=6
Req 3 - references350ms (± 0.97%)355ms (± 0.86%)+5ms (+ 1.28%)353ms361msp=0.043 n=6
Req 4 - navto290ms (± 0.42%)288ms (± 0.28%)~287ms289msp=0.120 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo68ms (± 1.61%)67ms (± 0.77%)~67ms68msp=0.247 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen3,198ms (± 0.41%)3,196ms (± 0.34%)~3,183ms3,212msp=0.810 n=6
Req 2 - geterr1,638ms (± 1.17%)1,637ms (± 0.80%)~1,621ms1,654msp=0.873 n=6
Req 3 - references105ms (± 1.17%)105ms (± 1.17%)~103ms106msp=1.000 n=6
Req 4 - navto358ms (± 1.26%)357ms (± 0.57%)~354ms360msp=1.000 n=6
Req 5 - completionInfo count3,136 (± 0.00%)3,136 (± 0.00%)~3,1363,136p=1.000 n=6
Req 5 - completionInfo426ms (± 1.53%)430ms (± 1.13%)~424ms438msp=0.374 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen2,518ms (± 1.00%)2,527ms (± 0.54%)~2,515ms2,549msp=0.873 n=6
Req 2 - geterr5,742ms (± 0.48%)5,765ms (± 0.26%)~5,747ms5,784msp=0.173 n=6
Req 3 - references354ms (± 1.22%)351ms (± 1.18%)~343ms355msp=0.294 n=6
Req 4 - navto280ms (± 0.89%)278ms (± 1.01%)~273ms280msp=0.305 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo82ms (± 5.51%)82ms (± 4.25%)~77ms86msp=0.806 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen2,688ms (± 0.61%)2,695ms (± 0.73%)~2,664ms2,712msp=0.630 n=6
Req 2 - geterr4,384ms (± 0.58%)4,375ms (± 0.38%)~4,352ms4,401msp=0.748 n=6
Req 3 - references363ms (± 0.86%)364ms (± 1.02%)~357ms367msp=0.622 n=6
Req 4 - navto287ms (± 1.14%)286ms (± 1.33%)~280ms289msp=1.000 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo73ms (± 1.65%)73ms (± 0.87%)~72ms74msp=0.673 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen3,371ms (± 0.17%)3,370ms (± 0.60%)~3,355ms3,410msp=0.229 n=6
Req 2 - geterr1,864ms (± 5.71%)1,867ms (± 4.71%)~1,803ms2,038msp=0.688 n=6
Req 3 - references111ms (± 2.26%)113ms (± 2.65%)~110ms118msp=0.191 n=6
Req 4 - navto340ms (± 1.98%)345ms (± 2.16%)~333ms353msp=0.295 n=6
Req 5 - completionInfo count3,136 (± 0.00%)3,136 (± 0.00%)~3,1363,136p=1.000 n=6
Req 5 - completionInfo434ms (± 0.94%)435ms (± 0.98%)~430ms441msp=0.872 n=6
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen2,617ms (± 0.65%)2,622ms (± 0.24%)~2,610ms2,628msp=0.198 n=6
Req 2 - geterr6,082ms (± 0.39%)6,083ms (± 0.42%)~6,050ms6,119msp=1.000 n=6
Req 3 - references365ms (± 0.35%)365ms (± 0.22%)~364ms366msp=0.558 n=6
Req 4 - navto279ms (± 1.01%)277ms (± 0.60%)~275ms279msp=0.328 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo98ms (± 4.66%)101ms (± 0.54%)~100ms101msp=0.201 n=6
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen2,843ms (± 0.85%)2,850ms (± 0.61%)~2,823ms2,872msp=0.575 n=6
Req 2 - geterr4,534ms (± 2.25%)4,621ms (± 2.50%)~4,472ms4,714msp=0.128 n=6
Req 3 - references378ms (± 0.94%)382ms (± 0.35%)~380ms384msp=0.063 n=6
Req 4 - navto296ms (± 1.20%)294ms (± 1.42%)~290ms299msp=0.291 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo89ms (±10.97%)83ms (± 1.48%)~81ms84msp=0.288 n=6
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen3,698ms (± 0.76%)3,687ms (± 0.68%)~3,646ms3,717msp=0.810 n=6
Req 2 - geterr1,871ms (± 1.55%)1,851ms (± 2.23%)~1,805ms1,908msp=0.423 n=6
Req 3 - references128ms (± 3.39%)129ms (± 3.52%)~124ms136msp=0.809 n=6
Req 4 - navto376ms (± 0.85%)378ms (± 1.34%)~372ms386msp=0.810 n=6
Req 5 - completionInfo count3,136 (± 0.00%)3,136 (± 0.00%)~3,1363,136p=1.000 n=6
Req 5 - completionInfo448ms (± 2.32%)447ms (± 1.59%)~439ms459msp=0.630 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.15.1, x64)
BenchmarkNameIterations
Current528976
Baselinemain6

Startup

Comparison Report - main..52897
Metricmain52897DeltaBestWorstp-value
tsc-startup - node (v16.17.1, x64)
Execution time142.17ms (± 0.17%)143.27ms (± 0.23%)+1.10ms (+ 0.78%)142.55ms149.55msp=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time226.17ms (± 0.15%)229.15ms (± 0.39%)+2.98ms (+ 1.32%)226.88ms236.16msp=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time228.13ms (± 0.18%)230.23ms (± 0.31%)+2.10ms (+ 0.92%)228.49ms236.22msp=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time208.92ms (± 0.14%)210.72ms (± 0.23%)+1.81ms (+ 0.87%)209.36ms215.10msp=0.000 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
BenchmarkNameIterations
Current528976
Baselinemain6

Developer Information:

Download Benchmark

@fatcerberus

Copy link
Copy Markdown

Interestingly, 5.0 nightly catches the case where the comparer returns a literal 2 but not the a - b case. Playground

@jakebailey

Copy link
Copy Markdown
MemberAuthor

Yeah, then then leftover one is sort of the "known hole" as it has uses. Unfortunate.

@rbuckton

Copy link
Copy Markdown
Contributor

I've always wondered why we use Comparison rather than just number and do < 0/> 0/=== 0. Is there a performance benefit to using one or the other?

@rbuckton

Copy link
Copy Markdown
Contributor

I also noticed (but did not change) the fact that we use binary searches for things like import insertion with the assumption that the input is always sorted, but, I don't think this actually turns out to be the case all the time anymore?

Are there places in the code where we're doing a binary search on imports that we haven't previously checked are sorted? IIRC, that's the purpose of detectSortCaseSensitivity.

We have public "branded" types like SortedReadonlyArray and SortedArray that are intended to be used to signal something is sorted, but I've never been a fan of them because they are only sorted in relation to a specific Comparer, which isn't captured in the type. While they may be "sorted" in one respect, you cannot always safely use them as an argument that accepts a "sorted" array without also providing the comparer that was used, which makes the branded type somewhat misleading.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

I've always wondered why we use Comparison rather than just number and do < 0/> 0/=== 0. Is there a performance benefit to using one or the other?

I doubt it. But I think it's a little easier to understand.

While they may be "sorted" in one respect, you cannot always safely use them as an argument that accepts a "sorted" array without also providing the comparer that was used, which makes the branded type somewhat misleading.

Even so, I do like that even if you don't use the types always, you are forced to cast to a sorted array of you need to use them (depending), which does make one think twice about whether or not the array is actually sorted or not.

@rbuckton

Copy link
Copy Markdown
Contributor

While they may be "sorted" in one respect, you cannot always safely use them as an argument that accepts a "sorted" array without also providing the comparer that was used, which makes the branded type somewhat misleading.

Even so, I do like that even if you don't use the types always, you are forced to cast to a sorted array of you need to use them (depending), which does make one think twice about whether or not the array is actually sorted or not.

I'd almost rather have a data structure that encapsulates both the sorted array and the comparer, though I'm not sure that's going to be as efficient.

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@jakebailey@typescript-bot@DanielRosenwasser@fatcerberus@rbuckton