Skip to content

Avoid no-op export map updates #45238

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

Merged
merged 3 commits into from
Jul 30, 2021
Merged

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Jul 29, 2021

This is a follow-up to #44402. Internal teams with large projects have seen significant perf wins from that change (~20% reduction in build time) but I've stumbled onto some pathological cases where the change actually increases build time by ~50%.

The builder maintains two copies of the exported modules map - changes are accumulated in a copy so that they can be discarded if something invalidated the update. When the build does complete successfully, one ManyToManyPathMap is updated from another, which requires traversing both. In local measurements, each such update was taking 2-4 seconds (this is very project-specific) and there were 2000 in the course of building a single project. However, it turned out that the copy was never actually modified after its initialization, so all subsequent updates of the "real" map were no-ops. This change introduces a cheap way to determine that the cache hasn't changed.

I think we could probably use a more sophisticated method to handle these updates (e.g. accumulating only a delta), but I deliberately made the change very simple because we're so late in the 4.4 cycle.

amcasey added 2 commits July 29, 2021 11:05
...so that unchanged maps can be recognized without having to examine
their contents.
In practice, `updateExportedFilesMapFromCache` is called repeatedly
without the cache changing in between.  When this occurs, there's no
need to update the `BuilderState` (this was already the net effect, but
it took a long time to determine that no work was required).
@amcasey amcasey requested a review from andrewbranch July 29, 2021 18:21
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 29, 2021
@amcasey
Copy link
Member Author

amcasey commented Jul 29, 2021

For my local repro

4.2: 631.23s
4.4: 962.68s
PR: 279.44s

@amcasey
Copy link
Member Author

amcasey commented Jul 29, 2021

@DanielRosenwasser @RyanCavanaugh I think it's important to get this into 4.4 because I don't have a good sense of whether/which real world scenarios will see the large build time regression I noticed in my (contrived) local experiments.

addToMultimap(reverse, v, k);
}
});

if (changed) {
version++;
Copy link
Member Author

Choose a reason for hiding this comment

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

It's vitally important that this not miss a case where the map has actually changed - please double-check.

@amcasey
Copy link
Member Author

amcasey commented Jul 29, 2021

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 29, 2021

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

Update: The results are in!

@amcasey
Copy link
Member Author

amcasey commented Jul 29, 2021

As far as I know, the perf suite doesn't cover build mode, so I don't expect any changes.

Edit: confirmed

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..45238

Metric main 45238 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 347,516k (± 0.02%) 347,519k (± 0.02%) +2k (+ 0.00%) 347,357k 347,635k
Parse Time 1.89s (± 0.47%) 1.88s (± 0.56%) -0.01s (- 0.53%) 1.85s 1.89s
Bind Time 0.86s (± 0.55%) 0.86s (± 0.65%) +0.00s (+ 0.12%) 0.85s 0.87s
Check Time 5.37s (± 0.50%) 5.33s (± 0.63%) -0.04s (- 0.67%) 5.26s 5.41s
Emit Time 5.82s (± 0.35%) 5.82s (± 0.63%) -0.00s (- 0.05%) 5.77s 5.92s
Total Time 13.93s (± 0.28%) 13.88s (± 0.50%) -0.05s (- 0.33%) 13.77s 14.05s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,388k (± 0.03%) 203,446k (± 0.03%) +58k (+ 0.03%) 203,310k 203,558k
Parse Time 0.78s (± 0.51%) 0.79s (± 0.66%) +0.01s (+ 1.02%) 0.78s 0.80s
Bind Time 0.53s (± 1.40%) 0.52s (± 0.91%) -0.01s (- 1.88%) 0.52s 0.54s
Check Time 7.83s (± 0.68%) 7.80s (± 0.26%) -0.03s (- 0.33%) 7.76s 7.86s
Emit Time 2.44s (± 0.92%) 2.42s (± 0.78%) -0.02s (- 0.70%) 2.39s 2.48s
Total Time 11.58s (± 0.54%) 11.54s (± 0.25%) -0.04s (- 0.38%) 11.48s 11.61s
Monaco - node (v10.16.3, x64)
Memory used 340,547k (± 0.02%) 340,529k (± 0.03%) -18k (- 0.01%) 340,400k 340,820k
Parse Time 1.45s (± 0.86%) 1.46s (± 0.79%) +0.00s (+ 0.14%) 1.43s 1.48s
Bind Time 0.75s (± 0.82%) 0.75s (± 0.97%) -0.00s (- 0.13%) 0.73s 0.76s
Check Time 5.38s (± 0.63%) 5.37s (± 0.74%) -0.00s (- 0.04%) 5.29s 5.46s
Emit Time 3.16s (± 0.75%) 3.19s (± 1.05%) +0.03s (+ 0.82%) 3.13s 3.26s
Total Time 10.74s (± 0.29%) 10.77s (± 0.48%) +0.03s (+ 0.25%) 10.67s 10.87s
TFS - node (v10.16.3, x64)
Memory used 303,976k (± 0.01%) 304,017k (± 0.02%) +41k (+ 0.01%) 303,882k 304,119k
Parse Time 1.18s (± 0.49%) 1.19s (± 0.54%) +0.01s (+ 0.42%) 1.17s 1.20s
Bind Time 0.71s (± 0.99%) 0.71s (± 0.42%) -0.00s (- 0.14%) 0.70s 0.71s
Check Time 4.90s (± 0.58%) 4.89s (± 0.23%) -0.01s (- 0.16%) 4.86s 4.92s
Emit Time 3.33s (± 0.89%) 3.36s (± 1.07%) +0.03s (+ 0.81%) 3.24s 3.42s
Total Time 10.13s (± 0.48%) 10.15s (± 0.37%) +0.02s (+ 0.21%) 10.02s 10.21s
material-ui - node (v10.16.3, x64)
Memory used 469,644k (± 0.01%) 469,690k (± 0.01%) +46k (+ 0.01%) 469,607k 469,770k
Parse Time 1.73s (± 0.52%) 1.73s (± 0.72%) +0.01s (+ 0.58%) 1.71s 1.77s
Bind Time 0.66s (± 1.31%) 0.67s (± 0.78%) +0.01s (+ 1.06%) 0.66s 0.68s
Check Time 14.12s (± 0.32%) 14.24s (± 0.84%) +0.11s (+ 0.81%) 13.99s 14.54s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.51s (± 0.28%) 16.64s (± 0.68%) +0.13s (+ 0.79%) 16.38s 16.91s
Angular - node (v12.1.0, x64)
Memory used 325,541k (± 0.02%) 325,535k (± 0.02%) -5k (- 0.00%) 325,407k 325,681k
Parse Time 1.86s (± 0.78%) 1.85s (± 0.54%) -0.00s (- 0.05%) 1.84s 1.89s
Bind Time 0.84s (± 0.68%) 0.84s (± 0.77%) -0.00s (- 0.24%) 0.83s 0.85s
Check Time 5.17s (± 0.16%) 5.19s (± 0.63%) +0.02s (+ 0.45%) 5.13s 5.29s
Emit Time 6.04s (± 0.57%) 6.05s (± 1.05%) +0.01s (+ 0.17%) 5.95s 6.27s
Total Time 13.90s (± 0.26%) 13.94s (± 0.64%) +0.03s (+ 0.24%) 13.82s 14.24s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,886k (± 0.05%) 190,749k (± 0.08%) -137k (- 0.07%) 190,161k 190,890k
Parse Time 0.78s (± 0.71%) 0.78s (± 0.88%) -0.00s (- 0.39%) 0.76s 0.79s
Bind Time 0.54s (± 0.89%) 0.53s (± 0.92%) -0.00s (- 0.56%) 0.53s 0.55s
Check Time 7.28s (± 0.56%) 7.30s (± 0.65%) +0.02s (+ 0.29%) 7.23s 7.45s
Emit Time 2.42s (± 0.77%) 2.45s (± 1.20%) +0.03s (+ 1.24%) 2.39s 2.51s
Total Time 11.01s (± 0.47%) 11.06s (± 0.55%) +0.04s (+ 0.40%) 10.94s 11.24s
Monaco - node (v12.1.0, x64)
Memory used 323,640k (± 0.02%) 323,721k (± 0.02%) +81k (+ 0.03%) 323,574k 323,881k
Parse Time 1.42s (± 0.59%) 1.43s (± 0.66%) +0.01s (+ 0.42%) 1.41s 1.45s
Bind Time 0.72s (± 0.41%) 0.72s (± 0.90%) +0.00s (+ 0.00%) 0.71s 0.73s
Check Time 5.24s (± 0.60%) 5.24s (± 0.50%) -0.00s (- 0.06%) 5.20s 5.33s
Emit Time 3.18s (± 0.61%) 3.22s (± 0.85%) +0.04s (+ 1.16%) 3.16s 3.27s
Total Time 10.56s (± 0.35%) 10.60s (± 0.43%) +0.04s (+ 0.35%) 10.50s 10.74s
TFS - node (v12.1.0, x64)
Memory used 288,663k (± 0.02%) 288,678k (± 0.02%) +15k (+ 0.01%) 288,530k 288,803k
Parse Time 1.20s (± 0.63%) 1.20s (± 0.69%) 0.00s ( 0.00%) 1.19s 1.23s
Bind Time 0.70s (± 0.82%) 0.70s (± 1.00%) +0.00s (+ 0.14%) 0.69s 0.72s
Check Time 4.84s (± 0.40%) 4.83s (± 0.55%) -0.01s (- 0.17%) 4.77s 4.88s
Emit Time 3.36s (± 1.14%) 3.38s (± 1.40%) +0.02s (+ 0.65%) 3.30s 3.51s
Total Time 10.10s (± 0.56%) 10.12s (± 0.53%) +0.02s (+ 0.15%) 10.00s 10.29s
material-ui - node (v12.1.0, x64)
Memory used 448,432k (± 0.01%) 448,278k (± 0.08%) -155k (- 0.03%) 446,924k 448,491k
Parse Time 1.72s (± 0.59%) 1.72s (± 0.68%) +0.00s (+ 0.00%) 1.69s 1.74s
Bind Time 0.65s (± 0.86%) 0.65s (± 0.99%) +0.00s (+ 0.62%) 0.64s 0.67s
Check Time 12.69s (± 0.39%) 12.83s (± 1.13%) +0.14s (+ 1.12%) 12.66s 13.21s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.06s (± 0.32%) 15.20s (± 1.03%) +0.15s (+ 0.98%) 15.01s 15.60s
Angular - node (v14.15.1, x64)
Memory used 324,158k (± 0.01%) 324,164k (± 0.01%) +7k (+ 0.00%) 324,102k 324,215k
Parse Time 1.87s (± 0.56%) 1.88s (± 0.70%) +0.01s (+ 0.75%) 1.86s 1.92s
Bind Time 0.89s (± 1.35%) 0.90s (± 0.55%) +0.00s (+ 0.22%) 0.89s 0.91s
Check Time 5.20s (± 0.21%) 5.21s (± 0.56%) +0.01s (+ 0.27%) 5.15s 5.28s
Emit Time 6.15s (± 0.42%) 6.15s (± 0.44%) -0.00s (- 0.06%) 6.09s 6.21s
Total Time 14.11s (± 0.22%) 14.14s (± 0.33%) +0.03s (+ 0.18%) 14.04s 14.23s
Compiler-Unions - node (v14.15.1, x64)
Memory used 191,442k (± 0.60%) 190,810k (± 0.61%) -633k (- 0.33%) 189,499k 192,788k
Parse Time 0.80s (± 0.42%) 0.81s (± 1.07%) +0.01s (+ 0.62%) 0.80s 0.84s
Bind Time 0.56s (± 0.72%) 0.56s (± 0.93%) +0.00s (+ 0.36%) 0.55s 0.58s
Check Time 7.49s (± 0.71%) 7.45s (± 0.34%) -0.04s (- 0.59%) 7.38s 7.49s
Emit Time 2.43s (± 0.82%) 2.43s (± 0.84%) +0.00s (+ 0.16%) 2.39s 2.50s
Total Time 11.28s (± 0.54%) 11.25s (± 0.25%) -0.03s (- 0.27%) 11.16s 11.30s
Monaco - node (v14.15.1, x64)
Memory used 322,493k (± 0.00%) 322,496k (± 0.01%) +3k (+ 0.00%) 322,454k 322,526k
Parse Time 1.48s (± 0.81%) 1.48s (± 0.90%) +0.00s (+ 0.07%) 1.45s 1.51s
Bind Time 0.75s (± 0.00%) 0.75s (± 0.86%) +0.00s (+ 0.27%) 0.74s 0.77s
Check Time 5.19s (± 0.61%) 5.18s (± 0.40%) -0.02s (- 0.31%) 5.13s 5.23s
Emit Time 3.20s (± 0.57%) 3.23s (± 1.08%) +0.02s (+ 0.69%) 3.17s 3.33s
Total Time 10.63s (± 0.39%) 10.64s (± 0.43%) +0.01s (+ 0.07%) 10.56s 10.80s
TFS - node (v14.15.1, x64)
Memory used 287,669k (± 0.01%) 287,656k (± 0.01%) -13k (- 0.00%) 287,589k 287,735k
Parse Time 1.25s (± 1.99%) 1.26s (± 2.13%) +0.01s (+ 0.88%) 1.20s 1.34s
Bind Time 0.73s (± 3.35%) 0.73s (± 3.49%) +0.00s (+ 0.27%) 0.71s 0.83s
Check Time 4.82s (± 0.47%) 4.84s (± 0.41%) +0.02s (+ 0.41%) 4.79s 4.88s
Emit Time 3.48s (± 0.87%) 3.46s (± 0.46%) -0.02s (- 0.60%) 3.41s 3.49s
Total Time 10.28s (± 0.47%) 10.29s (± 0.26%) +0.01s (+ 0.11%) 10.21s 10.34s
material-ui - node (v14.15.1, x64)
Memory used 446,843k (± 0.00%) 446,846k (± 0.01%) +3k (+ 0.00%) 446,796k 446,889k
Parse Time 1.75s (± 0.47%) 1.76s (± 0.49%) +0.00s (+ 0.17%) 1.74s 1.77s
Bind Time 0.69s (± 0.94%) 0.69s (± 0.90%) +0.00s (+ 0.15%) 0.68s 0.70s
Check Time 12.82s (± 0.26%) 12.89s (± 0.92%) +0.07s (+ 0.56%) 12.74s 13.31s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.27s (± 0.25%) 15.34s (± 0.76%) +0.07s (+ 0.47%) 15.21s 15.76s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 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)
Benchmark Name Iterations
Current 45238 10
Baseline main 10

Developer Information:

Download Benchmark

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Seems fine to me, though there is some feedback you might want to consider. You should get a second look from @andrewbranch.

@amcasey amcasey merged commit 0f6e6ef into microsoft:main Jul 30, 2021
@amcasey amcasey deleted the ExportMapUpdate branch July 30, 2021 16:27
sheetalkamat added a commit that referenced this pull request Apr 5, 2022
sheetalkamat added a commit that referenced this pull request Apr 6, 2022
sheetalkamat added a commit that referenced this pull request Apr 11, 2022
sheetalkamat added a commit that referenced this pull request Apr 13, 2022
sheetalkamat added a commit that referenced this pull request Apr 14, 2022
sheetalkamat added a commit that referenced this pull request Apr 14, 2022
sheetalkamat added a commit that referenced this pull request Apr 15, 2022
…cache. (#48579)

* Revert "Avoid no-op export map updates (#45238)"

This reverts commit 0f6e6ef.

* Need to reset currentAffectedFilesExportedModulesMap after commiting to final exports map
Jack-Works pushed a commit to Jack-Works/TypeScript that referenced this pull request Apr 22, 2022
…cache. (microsoft#48579)

* Revert "Avoid no-op export map updates (microsoft#45238)"

This reverts commit 0f6e6ef.

* Need to reset currentAffectedFilesExportedModulesMap after commiting to final exports map
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.

4 participants