Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regular imports instead of require where possible #59017

Merged
merged 3 commits into from
Jun 25, 2024

Conversation

jakebailey
Copy link
Member

This is pulled out of #58419, since I think this is generally better and we can do it now.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 25, 2024
@jakebailey
Copy link
Member Author

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 25, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
perf test this ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 192,704k (± 0.60%) 193,959k (± 0.99%) ~ 192,161k 195,778k p=0.128 n=6
Parse Time 1.58s (± 0.26%) 1.58s (± 0.48%) ~ 1.57s 1.59s p=1.000 n=6
Bind Time 0.86s (± 1.14%) 0.86s (± 0.73%) ~ 0.85s 0.87s p=0.733 n=6
Check Time 11.21s (± 0.23%) 11.19s (± 0.43%) ~ 11.12s 11.25s p=0.422 n=6
Emit Time 3.27s (± 0.32%) 3.27s (± 0.46%) ~ 3.26s 3.30s p=0.282 n=6
Total Time 16.91s (± 0.13%) 16.90s (± 0.28%) ~ 16.83s 16.96s p=0.810 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 944,114 944,114 ~ ~ ~ p=1.000 n=6
Types 407,050 407,050 ~ ~ ~ p=1.000 n=6
Memory used 1,218,311k (± 0.00%) 1,218,293k (± 0.00%) ~ 1,218,209k 1,218,378k p=0.575 n=6
Parse Time 7.96s (± 0.93%) 7.94s (± 0.31%) ~ 7.91s 7.98s p=0.573 n=6
Bind Time 2.23s (± 0.23%) 2.24s (± 0.24%) +0.01s (+ 0.37%) 2.23s 2.24s p=0.038 n=6
Check Time 35.74s (± 0.29%) 35.72s (± 0.34%) ~ 35.50s 35.86s p=0.809 n=6
Emit Time 16.12s (± 0.42%) 16.16s (± 0.32%) ~ 16.12s 16.26s p=0.687 n=6
Total Time 62.06s (± 0.29%) 62.05s (± 0.24%) ~ 61.80s 62.22s p=1.000 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,135,096 2,135,096 ~ ~ ~ p=1.000 n=6
Types 927,168 927,168 ~ ~ ~ p=1.000 n=6
Memory used 2,117,354k (± 0.01%) 2,117,357k (± 0.01%) ~ 2,117,234k 2,117,506k p=0.810 n=6
Parse Time 7.91s (± 0.27%) 7.92s (± 0.37%) ~ 7.88s 7.96s p=0.468 n=6
Bind Time 2.76s (± 0.61%) 2.77s (± 0.62%) ~ 2.74s 2.79s p=0.465 n=6
Check Time 83.53s (± 0.32%) 83.85s (± 0.19%) ~ 83.69s 84.07s p=0.093 n=6
Emit Time 0.16s (± 4.65%) 0.16s (± 4.65%) ~ 0.15s 0.17s p=1.000 n=6
Total Time 94.36s (± 0.28%) 94.70s (± 0.16%) +0.34s (+ 0.36%) 94.51s 94.91s p=0.031 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,230,869 1,231,459 +590 (+ 0.05%) ~ ~ p=0.001 n=6
Types 261,077 261,178 +101 (+ 0.04%) ~ ~ p=0.001 n=6
Memory used 2,356,017k (± 1.01%) 2,347,553k (± 0.03%) ~ 2,346,575k 2,348,323k p=0.173 n=6
Parse Time 5.98s (± 0.53%) 6.00s (± 1.29%) ~ 5.92s 6.12s p=0.936 n=6
Bind Time 2.26s (± 0.66%) 2.27s (± 0.60%) ~ 2.26s 2.29s p=0.369 n=6
Check Time 39.77s (± 0.54%) 40.27s (± 0.24%) +0.50s (+ 1.26%) 40.15s 40.37s p=0.005 n=6
Emit Time 3.21s (± 1.51%) 3.24s (± 1.87%) ~ 3.16s 3.30s p=0.335 n=6
Total Time 51.22s (± 0.42%) 51.80s (± 0.30%) +0.58s (+ 1.13%) 51.62s 51.98s p=0.005 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,230,869 1,231,459 +590 (+ 0.05%) ~ ~ p=0.001 n=6
Types 261,077 261,178 +101 (+ 0.04%) ~ ~ p=0.001 n=6
Memory used 2,421,915k (± 0.02%) 2,423,132k (± 0.02%) +1,218k (+ 0.05%) 2,422,625k 2,423,855k p=0.013 n=6
Parse Time 5.16s (± 0.53%) 5.22s (± 0.84%) +0.06s (+ 1.26%) 5.15s 5.28s p=0.030 n=6
Bind Time 1.68s (± 0.48%) 1.70s (± 1.05%) ~ 1.67s 1.72s p=0.085 n=6
Check Time 34.16s (± 0.37%) 34.51s (± 0.19%) +0.35s (+ 1.03%) 34.41s 34.60s p=0.005 n=6
Emit Time 2.68s (± 2.29%) 2.76s (± 1.81%) ~ 2.67s 2.81s p=0.066 n=6
Total Time 43.72s (± 0.31%) 44.21s (± 0.24%) +0.50s (+ 1.13%) 44.12s 44.41s p=0.005 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 258,577 258,577 ~ ~ ~ p=1.000 n=6
Types 104,827 104,827 ~ ~ ~ p=1.000 n=6
Memory used 428,182k (± 0.01%) 428,194k (± 0.01%) ~ 428,158k 428,273k p=0.810 n=6
Parse Time 2.75s (± 0.67%) 2.74s (± 0.72%) ~ 2.71s 2.76s p=0.935 n=6
Bind Time 1.11s (± 1.51%) 1.11s (± 1.75%) ~ 1.08s 1.13s p=1.000 n=6
Check Time 15.08s (± 0.29%) 15.07s (± 0.37%) ~ 14.97s 15.14s p=1.000 n=6
Emit Time 1.16s (± 1.33%) 1.15s (± 0.95%) ~ 1.13s 1.16s p=0.359 n=6
Total Time 20.10s (± 0.20%) 20.07s (± 0.34%) ~ 19.97s 20.17s p=0.574 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,565 224,565 ~ ~ ~ p=1.000 n=6
Types 93,734 93,734 ~ ~ ~ p=1.000 n=6
Memory used 369,470k (± 0.03%) 369,426k (± 0.03%) ~ 369,341k 369,604k p=0.471 n=6
Parse Time 2.31s (± 0.51%) 2.31s (± 0.33%) ~ 2.30s 2.32s p=0.933 n=6
Bind Time 1.34s (± 1.46%) 1.33s (± 1.32%) ~ 1.31s 1.36s p=0.176 n=6
Check Time 13.13s (± 0.22%) 13.15s (± 0.28%) ~ 13.11s 13.20s p=0.466 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 16.79s (± 0.25%) 16.79s (± 0.27%) ~ 16.74s 16.86s p=0.873 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,878,705 2,878,705 ~ ~ ~ p=1.000 n=6
Types 975,213 975,213 ~ ~ ~ p=1.000 n=6
Memory used 3,041,995k (± 0.00%) 3,041,998k (± 0.00%) ~ 3,041,926k 3,042,059k p=1.000 n=6
Parse Time 13.51s (± 0.41%) 13.48s (± 0.30%) ~ 13.41s 13.52s p=0.684 n=6
Bind Time 4.15s (± 0.34%) 4.19s (± 1.99%) ~ 4.15s 4.36s p=0.245 n=6
Check Time 72.82s (± 0.23%) 72.98s (± 0.21%) ~ 72.79s 73.20s p=0.092 n=6
Emit Time 23.91s (± 1.00%) 23.86s (± 0.17%) ~ 23.78s 23.90s p=0.575 n=6
Total Time 114.38s (± 0.24%) 114.51s (± 0.19%) ~ 114.22s 114.75s p=0.471 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 267,117 267,117 ~ ~ ~ p=1.000 n=6
Types 108,775 108,775 ~ ~ ~ p=1.000 n=6
Memory used 411,568k (± 0.03%) 411,537k (± 0.01%) ~ 411,464k 411,602k p=0.936 n=6
Parse Time 3.80s (± 0.56%) 3.81s (± 0.61%) ~ 3.78s 3.84s p=0.464 n=6
Bind Time 1.69s (± 0.61%) 1.68s (± 0.45%) ~ 1.67s 1.69s p=0.351 n=6
Check Time 16.70s (± 0.48%) 16.67s (± 0.23%) ~ 16.62s 16.72s p=0.686 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.19s (± 0.35%) 22.17s (± 0.17%) ~ 22.10s 22.20s p=1.000 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 525,251 525,251 ~ ~ ~ p=1.000 n=6
Types 178,574 178,574 ~ ~ ~ p=1.000 n=6
Memory used 462,894k (± 0.05%) 462,994k (± 0.07%) ~ 462,386k 463,267k p=0.298 n=6
Parse Time 2.65s (± 0.37%) 2.64s (± 0.57%) ~ 2.62s 2.66s p=0.360 n=6
Bind Time 0.98s (± 0.64%) 0.98s (± 0.53%) ~ 0.97s 0.98s p=0.386 n=6
Check Time 15.16s (± 0.43%) 15.16s (± 0.28%) ~ 15.08s 15.20s p=0.687 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 18.79s (± 0.33%) 18.78s (± 0.26%) ~ 18.69s 18.83s p=0.630 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,779ms (± 0.60%) 2,755ms (± 1.39%) ~ 2,705ms 2,797ms p=0.575 n=6
Req 2 - geterr 6,934ms (± 9.62%) 6,280ms (± 8.74%) ~ 6,022ms 7,399ms p=0.128 n=6
Req 3 - references 370ms (±10.38%) 358ms (±11.79%) ~ 318ms 397ms p=0.808 n=6
Req 4 - navto 341ms (± 0.16%) 340ms ~ ~ ~ p=0.071 n=6
Req 5 - completionInfo count 1,357 1,357 ~ ~ ~ p=1.000 n=6
Req 5 - completionInfo 131ms (± 0.39%) 132ms (± 1.17%) ~ 131ms 135ms p=0.523 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,412ms (± 0.72%) 2,431ms (± 0.40%) ~ 2,420ms 2,445ms p=0.054 n=6
Req 2 - geterr 3,797ms (± 0.15%) 3,797ms (± 0.24%) ~ 3,780ms 3,807ms p=0.688 n=6
Req 3 - references 276ms (± 0.85%) 278ms (± 0.20%) ~ 277ms 278ms p=0.228 n=6
Req 4 - navto 229ms (± 2.71%) 226ms (± 0.43%) ~ 225ms 227ms p=0.865 n=6
Req 5 - completionInfo count 1,519 1,519 ~ ~ ~ p=1.000 n=6
Req 5 - completionInfo 74ms (± 8.05%) 74ms (± 0.74%) ~ 73ms 74ms p=0.154 n=6
xstate-main-1-tsserver - node (v18.15.0, x64)
Req 1 - updateOpen 7,702ms (± 0.47%) 6,369ms (± 4.96%) 🟩-1,333ms (-17.31%) 6,215ms 7,013ms p=0.005 n=6
Req 2 - geterr 1,683ms (± 1.00%) 1,594ms (±11.50%) ~ 1,348ms 1,734ms p=0.689 n=6
Req 3 - references 111ms (± 5.00%) 105ms (± 0.52%) ~ 104ms 105ms p=0.152 n=6
Req 4 - navto 611ms (± 2.34%) 596ms (± 1.42%) -15ms (- 2.48%) 581ms 603ms p=0.029 n=6
Req 5 - completionInfo count 3,413 3,413 ~ ~ ~ p=1.000 n=6
Req 5 - completionInfo 1,274ms (± 2.17%) 1,245ms (± 0.77%) ~ 1,235ms 1,259ms p=0.128 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstate-main-1-tsserver - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 187.95ms (± 0.17%) 187.93ms (± 0.19%) ~ 186.20ms 191.43ms p=0.214 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 284.80ms (± 0.27%) 284.84ms (± 0.26%) ~ 278.07ms 287.68ms p=0.673 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 279.23ms (± 0.29%) 279.09ms (± 0.29%) -0.14ms (- 0.05%) 272.66ms 286.93ms p=0.000 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 338.88ms (± 0.30%) 338.67ms (± 0.29%) -0.21ms (- 0.06%) 330.51ms 348.20ms p=0.000 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@jakebailey jakebailey merged commit ef339af into microsoft:main Jun 25, 2024
28 checks passed
@jakebailey jakebailey deleted the use-imports branch June 25, 2024 21:00
Comment on lines +1 to +5
import childProcess from "child_process";
import fs from "fs";
import net from "net";
import os from "os";
import readline from "readline";
Copy link
Member

@DanielRosenwasser DanielRosenwasser Jul 3, 2024

Choose a reason for hiding this comment

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

Is there any risk now that these are unconditional imports?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this is the tsserver project which only runs in node.

@@ -326,7 +277,7 @@ export function initializeNodeSystem(): StartInput {

let cancellationToken: ts.server.ServerCancellationToken;
try {
const factory = require("./cancellationToken");
const factory = require("./cancellationToken.js");
Copy link

Choose a reason for hiding this comment

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

Hi, I came across this line running dependency-cruiser on the typescript codebase. After building, it's the only require/import that can't be resolved. I notice that this file, nodeServer, does not have a cancellationToken sibling file - is it possible that this is always throwing (seems like it could be, since the catch block silently catches the error and uses ts.server.nullCancellationToken)

Copy link
Member Author

Choose a reason for hiding this comment

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

This file should exist as a sibling. https://unpkg.com/browse/typescript@5.6.3/lib/cancellationToken.js

Are you running this tool on the built code, or the source?

Copy link
Member Author

Choose a reason for hiding this comment

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

(realistically, it's not clear to me why this is a separate file at all anyway)

Copy link

Choose a reason for hiding this comment

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

Oh I see. I'm running it on the source, so I guess it's missing some part of the build process that compiles src/tsserver/nodeServer.ts into lib/tsserver.js, and src/cancellationToken/cancellationToken.ts into lib/cancellationToken.js, is that right? (Something in Hereby?)

Would it not work as require("../cancellationToken/cancellationToken.js") (which I think is what would be correct for the source file structure)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that would not work. Our input source structure has nothing to do with our output source structure; it's bundled and placed in a different directory.

Copy link

Choose a reason for hiding this comment

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

Got it - thanks very much!

Copy link
Member Author

Choose a reason for hiding this comment

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

#60250 you've inspired me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants