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

Keep scriptInfo and project alive even after file delete till next file open #57492

Merged
merged 5 commits into from
Apr 12, 2024

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Feb 22, 2024

Some times when updating branches or doing npm ci, instead of file change event, we may get file delete followed by file create event.
This was previously handled not so efficiently as: as soon as we get delete event say on configFile for the project, we would remove the whole project from memory and schedule update for open files, only to get file create so end up creating project again.

With this change:

  1. 784e0ef When config file watched gets deleted, we defer removing/closing it and reuse if we get create event, we can just mark this project for update and remove its defer delete option. The deferred delete marked project is kept alive and acts as orphan project until next file open which is when we normally do gc on all projects and scriptInfos. Note we do something similar for inferred project so we can reuse it so its just extending that concept to configured project
  2. bd10117 For scriptInfos that are deleted, they are also kept around and watched till next file open, so we can reuse the text and version if it doesnt change. Eg npm ci can replace file with same text and this helps with file usage. Again these deferred removed on next file open.

Other two commits in the PR are tests before the change to cover for scenarios of file delete, recreate etc and refactoring

This should also help with #57196 when we would open more projects and configs to search for your default project

Without proper repro to measure perf reliably but in my dogfooding and from tests it seems to really help with the perf in these kind of scenarios. (No guarantee when timeout happens and how things will unfold to see if delete, create happen or not)

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Feb 22, 2024
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@jakebailey
Copy link
Member

@typescript-bot perf test this
@typescript-bot user test tsserver
@typescript-bot test tsserver top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 10, 2024

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

Command Status Results
perf test this ✅ Started 👀 Results
user test tsserver ✅ Started ✅ Results
test tsserver top100 ✅ Started

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests comparing main and refs/pull/57492/merge:

Everything looks good!

@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
Angular - node (v18.15.0, x64)
Memory used 295,880k (± 0.01%) 295,858k (± 0.01%) ~ 295,810k 295,916k p=0.575 n=6
Parse Time 3.21s (± 0.43%) 3.20s (± 0.78%) ~ 3.17s 3.23s p=0.391 n=6
Bind Time 0.98s (± 1.19%) 0.98s (± 1.36%) ~ 0.97s 1.00s p=0.858 n=6
Check Time 9.70s (± 0.46%) 9.70s (± 0.34%) ~ 9.67s 9.74s p=0.747 n=6
Emit Time 8.40s (± 0.50%) 8.44s (± 0.67%) ~ 8.36s 8.53s p=0.198 n=6
Total Time 22.28s (± 0.32%) 22.31s (± 0.27%) ~ 22.23s 22.40s p=0.470 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,896k (± 0.96%) 191,654k (± 0.02%) ~ 191,620k 191,711k p=0.065 n=6
Parse Time 2.03s (± 1.11%) 2.02s (± 1.11%) ~ 2.00s 2.06s p=0.285 n=6
Bind Time 1.07s (± 1.02%) 1.06s (± 1.39%) ~ 1.04s 1.08s p=0.360 n=6
Check Time 13.83s (± 0.27%) 13.83s (± 0.36%) ~ 13.75s 13.89s p=1.000 n=6
Emit Time 3.89s (± 0.39%) 3.87s (± 0.55%) ~ 3.84s 3.89s p=0.252 n=6
Total Time 20.81s (± 0.20%) 20.78s (± 0.25%) ~ 20.72s 20.85s p=0.295 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,692k (± 0.00%) 347,708k (± 0.00%) +16k (+ 0.00%) 347,686k 347,724k p=0.045 n=6
Parse Time 2.97s (± 0.51%) 2.98s (± 0.94%) ~ 2.94s 3.01s p=0.871 n=6
Bind Time 1.06s (± 0.49%) 1.07s (± 0.97%) ~ 1.05s 1.08s p=0.437 n=6
Check Time 8.21s (± 0.48%) 8.20s (± 0.39%) ~ 8.15s 8.23s p=1.000 n=6
Emit Time 4.83s (± 0.24%) 4.84s (± 0.16%) ~ 4.83s 4.85s p=0.136 n=6
Total Time 17.08s (± 0.19%) 17.08s (± 0.33%) ~ 16.99s 17.13s p=0.629 n=6
TFS - node (v18.15.0, x64)
Memory used 302,567k (± 0.01%) 302,573k (± 0.00%) ~ 302,553k 302,599k p=0.936 n=6
Parse Time 2.00s (± 0.88%) 2.01s (± 0.83%) ~ 1.99s 2.03s p=0.564 n=6
Bind Time 0.98s (± 1.12%) 0.98s (± 0.53%) ~ 0.97s 0.98s p=0.784 n=6
Check Time 6.30s (± 0.57%) 6.31s (± 0.50%) ~ 6.26s 6.35s p=0.571 n=6
Emit Time 3.60s (± 0.45%) 3.60s (± 0.35%) ~ 3.58s 3.61s p=0.681 n=6
Total Time 12.88s (± 0.35%) 12.89s (± 0.27%) ~ 12.83s 12.93s p=0.520 n=6
material-ui - node (v18.15.0, x64)
Memory used 510,565k (± 0.01%) 510,560k (± 0.01%) ~ 510,519k 510,616k p=0.689 n=6
Parse Time 3.19s (± 0.87%) 3.20s (± 0.78%) ~ 3.17s 3.24s p=0.806 n=6
Bind Time 1.17s (± 0.35%) 1.18s (± 1.07%) ~ 1.17s 1.20s p=0.057 n=6
Check Time 20.50s (± 0.31%) 20.46s (± 0.39%) ~ 20.32s 20.56s p=0.575 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 24.86s (± 0.29%) 24.84s (± 0.35%) ~ 24.70s 24.94s p=0.936 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,742,689k (± 0.00%) 1,742,708k (± 0.00%) ~ 1,742,649k 1,742,786k p=0.575 n=6
Parse Time 7.84s (± 0.41%) 7.86s (± 0.82%) ~ 7.79s 7.98s p=0.936 n=6
Bind Time 2.73s (± 0.45%) 2.73s (± 0.19%) ~ 2.72s 2.73s p=0.672 n=6
Check Time 66.44s (± 0.73%) 66.39s (± 0.24%) ~ 66.16s 66.55s p=0.873 n=6
Emit Time 0.15s (± 3.53%) 0.15s (± 3.53%) ~ 0.15s 0.16s p=1.000 n=6
Total Time 77.17s (± 0.62%) 77.13s (± 0.23%) ~ 76.82s 77.28s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,301,244k (± 0.03%) 2,302,560k (± 0.03%) +1,316k (+ 0.06%) 2,301,700k 2,303,415k p=0.020 n=6
Parse Time 5.00s (± 1.11%) 5.00s (± 1.07%) ~ 4.92s 5.07s p=1.000 n=6
Bind Time 1.88s (± 0.99%) 1.90s (± 2.73%) ~ 1.85s 2.00s p=0.333 n=6
Check Time 33.65s (± 0.32%) 33.65s (± 0.43%) ~ 33.37s 33.78s p=0.936 n=6
Emit Time 2.63s (± 2.80%) 2.62s (± 2.14%) ~ 2.52s 2.66s p=0.810 n=6
Total Time 43.17s (± 0.46%) 43.18s (± 0.36%) ~ 42.96s 43.42s p=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Memory used 2,376,842k (± 0.05%) 2,377,496k (± 0.06%) ~ 2,375,434k 2,379,236k p=0.378 n=6
Parse Time 7.71s (± 0.54%) 7.62s (± 0.74%) -0.09s (- 1.19%) 7.52s 7.69s p=0.020 n=6
Bind Time 2.50s (± 0.55%) 2.51s (± 0.82%) ~ 2.48s 2.54s p=0.250 n=6
Check Time 49.50s (± 0.63%) 49.34s (± 0.35%) ~ 49.10s 49.53s p=0.471 n=6
Emit Time 3.88s (± 2.04%) 4.05s (± 5.99%) ~ 3.77s 4.33s p=0.336 n=6
Total Time 63.59s (± 0.54%) 63.53s (± 0.63%) ~ 62.87s 64.09s p=0.810 n=6
self-compiler - node (v18.15.0, x64)
Memory used 418,308k (± 0.01%) 418,338k (± 0.01%) ~ 418,299k 418,385k p=0.261 n=6
Parse Time 3.38s (± 0.64%) 3.37s (± 0.71%) ~ 3.33s 3.40s p=0.332 n=6
Bind Time 1.30s (± 1.15%) 1.32s (± 1.47%) ~ 1.29s 1.34s p=0.220 n=6
Check Time 17.82s (± 0.41%) 17.83s (± 0.38%) ~ 17.75s 17.91s p=0.575 n=6
Emit Time 1.36s (± 0.90%) 1.38s (± 1.45%) ~ 1.36s 1.41s p=0.251 n=6
Total Time 23.88s (± 0.35%) 23.90s (± 0.40%) ~ 23.76s 24.01s p=0.686 n=6
vscode - node (v18.15.0, x64)
Memory used 2,906,112k (± 0.00%) 2,906,112k (± 0.00%) ~ 2,906,053k 2,906,174k p=1.000 n=6
Parse Time 13.01s (± 0.38%) 12.98s (± 0.40%) ~ 12.92s 13.05s p=0.686 n=6
Bind Time 4.08s (± 0.26%) 4.07s (± 0.39%) ~ 4.06s 4.10s p=0.508 n=6
Check Time 71.35s (± 0.57%) 71.46s (± 0.20%) ~ 71.22s 71.56s p=0.228 n=6
Emit Time 19.32s (± 0.94%) 19.41s (± 0.70%) ~ 19.19s 19.55s p=0.470 n=6
Total Time 107.76s (± 0.45%) 107.92s (± 0.20%) ~ 107.60s 108.14s p=0.298 n=6
webpack - node (v18.15.0, x64)
Memory used 408,657k (± 0.01%) 408,672k (± 0.03%) ~ 408,558k 408,923k p=0.689 n=6
Parse Time 3.87s (± 0.56%) 3.86s (± 0.68%) ~ 3.83s 3.90s p=0.808 n=6
Bind Time 1.67s (± 0.70%) 1.67s (± 0.93%) ~ 1.65s 1.69s p=1.000 n=6
Check Time 16.68s (± 0.09%) 16.64s (± 0.25%) ~ 16.58s 16.70s p=0.063 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.22s (± 0.08%) 22.17s (± 0.29%) ~ 22.09s 22.27s p=0.092 n=6
xstate - node (v18.15.0, x64)
Memory used 670,797k (± 0.01%) 670,818k (± 0.02%) ~ 670,670k 671,080k p=0.936 n=6
Parse Time 4.98s (± 0.82%) 4.96s (± 0.88%) ~ 4.90s 5.02s p=0.377 n=6
Bind Time 2.30s (± 0.55%) 2.30s (± 0.93%) ~ 2.27s 2.32s p=0.683 n=6
Check Time 4.22s (± 1.04%) 4.24s (± 0.35%) ~ 4.23s 4.26s p=0.287 n=6
Emit Time 0.03s (± 0.00%) 0.03s (±12.88%) ~ 0.03s 0.04s p=0.405 n=6
Total Time 11.54s (± 0.56%) 11.54s (± 0.41%) ~ 11.47s 11.60s p=1.000 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - 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)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - 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,832ms (± 0.88%) 2,845ms (± 0.78%) ~ 2,810ms 2,864ms p=0.335 n=6
Req 2 - geterr 6,045ms (± 1.72%) 6,047ms (± 0.61%) ~ 5,997ms 6,089ms p=0.471 n=6
Req 3 - references 343ms (± 1.04%) 360ms (± 9.00%) ~ 344ms 426ms p=0.054 n=6
Req 4 - navto 285ms (± 6.72%) 289ms (± 8.08%) ~ 276ms 336ms p=0.517 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 105ms (± 9.48%) 109ms (± 7.33%) ~ 99ms 122ms p=0.285 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,478ms (± 1.24%) 2,514ms (± 0.99%) ~ 2,482ms 2,540ms p=0.092 n=6
Req 2 - geterr 3,746ms (± 0.28%) 3,750ms (± 0.20%) ~ 3,738ms 3,761ms p=0.469 n=6
Req 3 - references 309ms (± 1.65%) 308ms (± 1.70%) ~ 301ms 312ms p=0.746 n=6
Req 4 - navto 229ms (± 0.24%) 228ms (± 0.18%) ~ 228ms 229ms p=0.282 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 84ms (± 0.00%) 83ms (± 1.96%) ~ 80ms 84ms p=0.405 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 3,832ms (± 0.48%) 3,827ms (± 0.72%) ~ 3,803ms 3,878ms p=0.572 n=6
Req 2 - geterr 2,178ms (± 0.57%) 2,183ms (± 0.84%) ~ 2,160ms 2,204ms p=0.470 n=6
Req 3 - references 134ms (± 2.13%) 195ms (± 1.89%) 🔻+61ms (+45.33%) 191ms 199ms p=0.005 n=6
Req 4 - navto 527ms (± 0.74%) 543ms (± 2.10%) +15ms (+ 2.91%) 526ms 554ms p=0.036 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 432ms (± 0.90%) 419ms (± 0.85%) -13ms (- 2.94%) 416ms 425ms p=0.006 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)
  • xstateTSServer - 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 222.77ms (± 0.16%) 222.78ms (± 0.19%) ~ 220.81ms 230.88ms p=0.523 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 227.06ms (± 0.16%) 227.20ms (± 0.16%) +0.14ms (+ 0.06%) 225.86ms 233.28ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 272.35ms (± 0.29%) 271.94ms (± 0.30%) -0.41ms (- 0.15%) 265.19ms 283.16ms p=0.000 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 331.83ms (± 0.31%) 331.64ms (± 0.30%) -0.19ms (- 0.06%) 323.33ms 338.98ms p=0.001 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

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

This seems fine to me (though I don't know how to physically test it), though I think my main concern are API users who expect that closing a file actually frees its resources. I'm not sure if ts-eslint actually closes any files, though.

@sheetalkamat sheetalkamat merged commit 4e29496 into main Apr 12, 2024
25 checks passed
@sheetalkamat sheetalkamat deleted the fileChange branch April 12, 2024 17:43
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
None yet
Development

Successfully merging this pull request may close these issues.

3 participants