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

More structural comparisons during variance computation #45628

Closed
wants to merge 6 commits into from

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Aug 29, 2021

This PR fixes variance computation to perform structural comparisons for all type alias instantiations and object type instantiations with one or more variance markers as type arguments. Further discussion of the fix here.

Fixes #44572.

@ahejlsberg
Copy link
Member Author

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 29, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..45628

Metric main 45628 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 351,380k (± 0.02%) 351,538k (± 0.02%) +158k (+ 0.04%) 351,421k 351,718k
Parse Time 1.91s (± 0.51%) 1.90s (± 0.68%) -0.01s (- 0.73%) 1.88s 1.92s
Bind Time 0.85s (± 0.85%) 0.86s (± 0.78%) +0.00s (+ 0.59%) 0.85s 0.88s
Check Time 5.39s (± 0.35%) 5.38s (± 0.41%) -0.02s (- 0.28%) 5.33s 5.42s
Emit Time 5.84s (± 0.82%) 5.84s (± 0.69%) -0.00s (- 0.09%) 5.73s 5.94s
Total Time 14.00s (± 0.34%) 13.96s (± 0.43%) -0.03s (- 0.24%) 13.81s 14.10s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,436k (± 0.03%) 203,572k (± 0.04%) +136k (+ 0.07%) 203,439k 203,802k
Parse Time 0.78s (± 0.83%) 0.78s (± 1.00%) -0.00s (- 0.38%) 0.76s 0.79s
Bind Time 0.53s (± 1.32%) 0.52s (± 1.34%) -0.01s (- 1.51%) 0.50s 0.53s
Check Time 7.84s (± 0.49%) 7.83s (± 0.59%) -0.01s (- 0.10%) 7.75s 7.94s
Emit Time 2.46s (± 0.99%) 2.42s (± 0.73%) -0.04s (- 1.55%) 2.39s 2.46s
Total Time 11.61s (± 0.48%) 11.56s (± 0.44%) -0.05s (- 0.46%) 11.45s 11.70s
Monaco - node (v10.16.3, x64)
Memory used 340,620k (± 0.02%) 340,641k (± 0.01%) +21k (+ 0.01%) 340,558k 340,735k
Parse Time 1.45s (± 0.94%) 1.45s (± 0.61%) +0.00s (+ 0.28%) 1.43s 1.48s
Bind Time 0.75s (± 0.82%) 0.75s (± 0.49%) -0.01s (- 0.67%) 0.74s 0.75s
Check Time 5.42s (± 0.67%) 5.42s (± 0.31%) -0.01s (- 0.11%) 5.37s 5.44s
Emit Time 3.17s (± 0.72%) 3.15s (± 0.60%) -0.02s (- 0.72%) 3.12s 3.21s
Total Time 10.80s (± 0.31%) 10.77s (± 0.30%) -0.03s (- 0.29%) 10.72s 10.86s
TFS - node (v10.16.3, x64)
Memory used 304,081k (± 0.03%) 304,016k (± 0.02%) -65k (- 0.02%) 303,857k 304,129k
Parse Time 1.18s (± 0.47%) 1.18s (± 0.47%) +0.00s (+ 0.34%) 1.17s 1.20s
Bind Time 0.71s (± 0.81%) 0.71s (± 0.63%) -0.00s (- 0.14%) 0.70s 0.72s
Check Time 4.94s (± 0.50%) 4.94s (± 0.47%) -0.00s (- 0.02%) 4.88s 4.99s
Emit Time 3.32s (± 1.28%) 3.31s (± 1.09%) -0.02s (- 0.48%) 3.22s 3.39s
Total Time 10.15s (± 0.57%) 10.14s (± 0.49%) -0.01s (- 0.09%) 9.99s 10.22s
material-ui - node (v10.16.3, x64)
Memory used 469,829k (± 0.01%) 470,086k (± 0.01%) +257k (+ 0.05%) 470,007k 470,173k
Parse Time 1.72s (± 0.44%) 1.72s (± 0.41%) -0.00s (- 0.17%) 1.71s 1.74s
Bind Time 0.67s (± 1.16%) 0.67s (± 0.92%) 0.00s ( 0.00%) 0.66s 0.69s
Check Time 14.17s (± 0.35%) 14.18s (± 0.33%) +0.01s (+ 0.06%) 14.06s 14.25s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.56s (± 0.33%) 16.57s (± 0.28%) +0.01s (+ 0.03%) 16.46s 16.64s
Angular - node (v12.1.0, x64)
Memory used 329,205k (± 0.08%) 329,446k (± 0.13%) +241k (+ 0.07%) 327,783k 329,826k
Parse Time 1.89s (± 0.78%) 1.87s (± 0.50%) -0.01s (- 0.79%) 1.86s 1.90s
Bind Time 0.84s (± 0.56%) 0.84s (± 0.69%) 0.00s ( 0.00%) 0.83s 0.86s
Check Time 5.27s (± 0.90%) 5.23s (± 0.53%) -0.03s (- 0.61%) 5.19s 5.30s
Emit Time 6.13s (± 0.79%) 6.09s (± 0.63%) -0.03s (- 0.52%) 6.03s 6.17s
Total Time 14.12s (± 0.58%) 14.04s (± 0.40%) -0.08s (- 0.58%) 13.96s 14.18s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,897k (± 0.05%) 190,822k (± 0.13%) -75k (- 0.04%) 190,317k 191,119k
Parse Time 0.78s (± 0.90%) 0.77s (± 0.58%) -0.01s (- 1.15%) 0.76s 0.78s
Bind Time 0.54s (± 0.83%) 0.54s (± 0.93%) -0.00s (- 0.56%) 0.53s 0.55s
Check Time 7.39s (± 0.84%) 7.36s (± 0.79%) -0.03s (- 0.45%) 7.26s 7.55s
Emit Time 2.44s (± 0.66%) 2.46s (± 1.19%) +0.01s (+ 0.53%) 2.40s 2.52s
Total Time 11.16s (± 0.59%) 11.13s (± 0.68%) -0.03s (- 0.29%) 10.97s 11.36s
Monaco - node (v12.1.0, x64)
Memory used 323,717k (± 0.04%) 323,789k (± 0.02%) +72k (+ 0.02%) 323,702k 324,028k
Parse Time 1.44s (± 0.72%) 1.43s (± 0.40%) -0.01s (- 0.56%) 1.42s 1.44s
Bind Time 0.73s (± 0.55%) 0.72s (± 0.50%) -0.01s (- 0.96%) 0.72s 0.73s
Check Time 5.29s (± 0.29%) 5.28s (± 0.62%) -0.02s (- 0.28%) 5.22s 5.35s
Emit Time 3.21s (± 0.70%) 3.18s (± 0.67%) -0.03s (- 0.78%) 3.14s 3.23s
Total Time 10.67s (± 0.31%) 10.61s (± 0.53%) -0.05s (- 0.51%) 10.53s 10.73s
TFS - node (v12.1.0, x64)
Memory used 288,740k (± 0.02%) 288,808k (± 0.02%) +68k (+ 0.02%) 288,650k 288,945k
Parse Time 1.22s (± 0.83%) 1.20s (± 0.67%) -0.01s (- 1.15%) 1.18s 1.22s
Bind Time 0.70s (± 0.95%) 0.70s (± 1.09%) -0.00s (- 0.71%) 0.68s 0.71s
Check Time 4.86s (± 0.48%) 4.86s (± 0.43%) +0.00s (+ 0.04%) 4.82s 4.92s
Emit Time 3.37s (± 0.90%) 3.39s (± 0.76%) +0.02s (+ 0.50%) 3.36s 3.48s
Total Time 10.15s (± 0.46%) 10.15s (± 0.36%) -0.00s (- 0.01%) 10.06s 10.23s
material-ui - node (v12.1.0, x64)
Memory used 448,526k (± 0.06%) 448,264k (± 0.10%) -262k (- 0.06%) 447,260k 448,810k
Parse Time 1.74s (± 0.82%) 1.73s (± 0.55%) -0.01s (- 0.63%) 1.71s 1.75s
Bind Time 0.66s (± 0.93%) 0.65s (± 1.12%) -0.01s (- 1.36%) 0.64s 0.67s
Check Time 12.96s (± 0.50%) 12.95s (± 0.73%) -0.02s (- 0.12%) 12.76s 13.13s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.48%) 15.33s (± 0.62%) -0.03s (- 0.21%) 15.14s 15.53s
Angular - node (v14.15.1, x64)
Memory used 327,940k (± 0.01%) 328,188k (± 0.01%) +248k (+ 0.08%) 328,117k 328,241k
Parse Time 1.91s (± 0.71%) 1.90s (± 0.50%) -0.01s (- 0.68%) 1.88s 1.92s
Bind Time 0.88s (± 0.42%) 0.87s (± 0.42%) -0.00s (- 0.23%) 0.87s 0.88s
Check Time 5.28s (± 0.48%) 5.27s (± 0.49%) -0.01s (- 0.27%) 5.19s 5.32s
Emit Time 6.19s (± 0.68%) 6.17s (± 0.64%) -0.01s (- 0.21%) 6.12s 6.27s
Total Time 14.25s (± 0.49%) 14.21s (± 0.33%) -0.04s (- 0.27%) 14.09s 14.30s
Compiler-Unions - node (v14.15.1, x64)
Memory used 191,458k (± 0.60%) 190,917k (± 0.66%) -541k (- 0.28%) 188,674k 193,002k
Parse Time 0.81s (± 0.28%) 0.80s (± 0.69%) -0.01s (- 0.87%) 0.79s 0.81s
Bind Time 0.56s (± 0.79%) 0.56s (± 0.71%) -0.00s (- 0.18%) 0.55s 0.57s
Check Time 7.54s (± 0.46%) 7.50s (± 0.98%) -0.04s (- 0.52%) 7.40s 7.74s
Emit Time 2.43s (± 0.62%) 2.44s (± 2.04%) +0.01s (+ 0.45%) 2.39s 2.62s
Total Time 11.34s (± 0.30%) 11.31s (± 0.98%) -0.03s (- 0.29%) 11.16s 11.72s
Monaco - node (v14.15.1, x64)
Memory used 322,527k (± 0.00%) 322,528k (± 0.01%) +1k (+ 0.00%) 322,502k 322,578k
Parse Time 1.50s (± 0.64%) 1.49s (± 0.89%) -0.01s (- 0.40%) 1.47s 1.53s
Bind Time 0.76s (± 1.14%) 0.75s (± 0.45%) -0.01s (- 0.66%) 0.75s 0.76s
Check Time 5.26s (± 0.52%) 5.22s (± 0.62%) -0.04s (- 0.86%) 5.14s 5.28s
Emit Time 3.25s (± 0.85%) 3.21s (± 0.63%) -0.04s (- 1.20%) 3.16s 3.25s
Total Time 10.77s (± 0.44%) 10.68s (± 0.50%) -0.09s (- 0.83%) 10.54s 10.79s
TFS - node (v14.15.1, x64)
Memory used 287,700k (± 0.01%) 287,689k (± 0.01%) -11k (- 0.00%) 287,638k 287,713k
Parse Time 1.26s (± 2.23%) 1.25s (± 1.97%) -0.01s (- 0.48%) 1.19s 1.32s
Bind Time 0.73s (± 1.19%) 0.72s (± 1.90%) -0.00s (- 0.69%) 0.71s 0.77s
Check Time 4.90s (± 0.40%) 4.87s (± 0.35%) -0.03s (- 0.67%) 4.82s 4.90s
Emit Time 3.48s (± 0.61%) 3.45s (± 0.61%) -0.04s (- 1.03%) 3.39s 3.48s
Total Time 10.37s (± 0.42%) 10.29s (± 0.42%) -0.08s (- 0.75%) 10.20s 10.40s
material-ui - node (v14.15.1, x64)
Memory used 446,971k (± 0.00%) 447,085k (± 0.00%) +114k (+ 0.03%) 447,052k 447,119k
Parse Time 1.77s (± 0.55%) 1.76s (± 0.55%) -0.01s (- 0.68%) 1.75s 1.79s
Bind Time 0.69s (± 0.49%) 0.69s (± 0.94%) -0.00s (- 0.14%) 0.68s 0.70s
Check Time 13.06s (± 0.51%) 13.05s (± 0.64%) -0.01s (- 0.10%) 12.89s 13.23s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.52s (± 0.46%) 15.50s (± 0.54%) -0.03s (- 0.16%) 15.34s 15.69s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory10 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 45628 10
Baseline main 10

Developer Information:

Download Benchmark

@ahejlsberg
Copy link
Member Author

Performance looks good, even slightly improved, likely because we're no longer jamming an aliasTypeArgumentsContainsMarker property onto variance measurement type instantiations.

@ahejlsberg
Copy link
Member Author

The failed fourslash test appears to be a preexisting problem in the main branch.

function createTypeReference(target: GenericType, typeArguments: readonly Type[] | undefined): TypeReference {
const id = getTypeListId(typeArguments);
let type = target.instantiations.get(id);
if (!type) {
type = createObjectType(ObjectFlags.Reference, target.symbol) as TypeReference;
target.instantiations.set(id, type);
type.objectFlags |= typeArguments ? getPropagatingFlagsOfTypes(typeArguments, /*excludeKinds*/ 0) : 0;
type.objectFlags |= (typeArguments ? getPropagatingFlagsOfTypes(typeArguments, /*excludeKinds*/ 0) : 0) |
(containsMarkerType(typeArguments) ? ObjectFlags.MarkerType : 0);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just add MarkerType to PropagatingFlags?

Copy link
Member

Choose a reason for hiding this comment

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

I agree - it was a flag on the type/list before so we could avoid doing any kind of deep checks for markers and catch pretty much the exact type we initially make. It was a known shortcoming that we missed markers that flowed into other versions of the reference we're checking the variance of (known to me, at least - I thought it was an intentional performance tradeoff). This now catches if a Whatever<?, T> has a Whatever<T, ?> dependency (and forces structural comparison, rather than assuming covariance), but still misses a Whatever<{x: ?}, T> dependency. Shouldn't we go all the way and catch if the marker appears in the type argument list in any way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we'd identify any occurrence of a marker type, but it would require eager exploration which we know doesn't end well for many classes of types. Our variance measurement is effectively a balance between correctness and performance, and here we're moving a little further towards correctness. I know we've tried doing only structural comparisons when computing variance, but it isn't feasible. It just reveals the same problems with (almost) infinite types that we're trying to solve by doing variance measurement in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could add MarkerType to PropagatingFlags, but it wouldn't save us much and would require us to also include TypeFlags.TypeParameter in TypeFlags.ObjectFlagsType, which would mean an extra property on every instance that we otherwise don't need.

@DanielRosenwasser
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2021

Heya @DanielRosenwasser, I've started to run the extended test suite on this PR at 813b04b. You can monitor the build here.

@@ -12901,13 +12901,18 @@ namespace ts {
return result & ObjectFlags.PropagatingFlags;
}

function containsMarkerType(typeArguments: readonly Type[] | undefined) {
return some(typeArguments, t => t === markerSuperType || t === markerSubType || t === markerOtherType);
Copy link
Member

Choose a reason for hiding this comment

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

This check happens a few times - maybe just hoist it out to its own function and call it in reportUnmeasurableMarkers/reportUnreliableMarkers.

@typescript-bot
Copy link
Collaborator

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

@Andarist
Copy link
Contributor

Would it be possible to generate a playground for this PR?

@andrewbranch
Copy link
Member

andrewbranch commented Feb 17, 2022

I forget whether it checks out the head or merge commit—if the latter, it would need its merge conflicts fixed, but we can try.

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

Heya @andrewbranch, I've started to run the tarball bundle task on this PR at 82c02a7. You can monitor the build here.

@andrewbranch
Copy link
Member

@ahejlsberg @DanielRosenwasser did we have any big concerns over this or did we mostly forget about it? If we think we might want to merge it, let’s work on getting it in early for 4.7.

# Conflicts:
#	src/compiler/checker.ts
@ahejlsberg
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

Heya @ahejlsberg, I've started to run the diff-based community code test suite on this PR at 2e859a2. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..refs/pull/45628/merge

TypeScript-Node-Starter

1 of 1 projects failed to build with the old tsc

/mnt/ts_downloads/TypeScript-Node-Starter/tsconfig.json

  • error TS2589: Type instantiation is excessively deep and possibly infinite.
    • /mnt/ts_downloads/TypeScript-Node-Starter/src/models/User.ts(91,21)

@Andarist
Copy link
Contributor

@andrewbranch could you request a new tarball? the spawned task has failed but that was executed before the recent merge, perhaps a fresh build after this merge would succeed

@ahejlsberg
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 17, 2022

Heya @ahejlsberg, I've started to run the tarball bundle task on this PR at 2e859a2. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..45628

Metric main 45628 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 332,744k (± 0.08%) 333,078k (± 0.01%) +334k (+ 0.10%) 333,042k 333,141k
Parse Time 2.02s (± 0.46%) 2.04s (± 1.02%) +0.02s (+ 0.79%) 2.01s 2.10s
Bind Time 0.90s (± 1.01%) 0.89s (± 1.09%) -0.01s (- 1.11%) 0.88s 0.92s
Check Time 5.56s (± 0.39%) 5.53s (± 0.32%) -0.04s (- 0.65%) 5.49s 5.57s
Emit Time 6.26s (± 0.63%) 6.27s (± 0.77%) +0.02s (+ 0.24%) 6.12s 6.36s
Total Time 14.74s (± 0.30%) 14.73s (± 0.40%) -0.02s (- 0.10%) 14.51s 14.79s
Compiler-Unions - node (v14.15.1, x64)
Memory used 193,047k (± 0.61%) 192,560k (± 0.50%) -487k (- 0.25%) 191,887k 195,185k
Parse Time 0.85s (± 0.52%) 0.85s (± 0.55%) -0.00s (- 0.23%) 0.84s 0.86s
Bind Time 0.57s (± 0.88%) 0.57s (± 0.84%) +0.00s (+ 0.35%) 0.56s 0.58s
Check Time 7.43s (± 0.70%) 7.40s (± 0.57%) -0.03s (- 0.35%) 7.30s 7.47s
Emit Time 2.48s (± 0.71%) 2.46s (± 0.64%) -0.02s (- 0.61%) 2.43s 2.50s
Total Time 11.32s (± 0.46%) 11.28s (± 0.46%) -0.04s (- 0.38%) 11.15s 11.37s
Monaco - node (v14.15.1, x64)
Memory used 325,015k (± 0.00%) 325,020k (± 0.01%) +4k (+ 0.00%) 324,968k 325,049k
Parse Time 1.56s (± 0.69%) 1.57s (± 0.57%) +0.00s (+ 0.26%) 1.55s 1.59s
Bind Time 0.78s (± 0.88%) 0.78s (± 0.88%) -0.00s (- 0.00%) 0.76s 0.79s
Check Time 5.40s (± 0.40%) 5.42s (± 0.55%) +0.02s (+ 0.30%) 5.32s 5.46s
Emit Time 3.29s (± 0.56%) 3.27s (± 0.97%) -0.01s (- 0.33%) 3.21s 3.35s
Total Time 11.02s (± 0.29%) 11.03s (± 0.47%) +0.01s (+ 0.07%) 10.88s 11.14s
TFS - node (v14.15.1, x64)
Memory used 288,580k (± 0.01%) 288,614k (± 0.01%) +34k (+ 0.01%) 288,570k 288,681k
Parse Time 1.31s (± 1.78%) 1.29s (± 0.73%) -0.01s (- 0.99%) 1.27s 1.31s
Bind Time 0.73s (± 0.67%) 0.74s (± 0.75%) +0.00s (+ 0.54%) 0.72s 0.75s
Check Time 5.06s (± 0.63%) 5.06s (± 0.52%) -0.00s (- 0.08%) 4.99s 5.12s
Emit Time 3.54s (± 0.31%) 3.56s (± 0.47%) +0.01s (+ 0.40%) 3.51s 3.60s
Total Time 10.65s (± 0.54%) 10.65s (± 0.31%) +0.00s (+ 0.04%) 10.56s 10.72s
material-ui - node (v14.15.1, x64)
Memory used 446,057k (± 0.06%) 446,170k (± 0.06%) +113k (+ 0.03%) 445,239k 446,375k
Parse Time 1.85s (± 0.63%) 1.85s (± 0.35%) -0.01s (- 0.38%) 1.83s 1.86s
Bind Time 0.69s (± 0.52%) 0.69s (± 1.01%) -0.00s (- 0.43%) 0.68s 0.71s
Check Time 12.91s (± 0.66%) 12.93s (± 1.08%) +0.02s (+ 0.16%) 12.68s 13.35s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.46s (± 0.57%) 15.47s (± 0.92%) +0.01s (+ 0.08%) 15.23s 15.91s
xstate - node (v14.15.1, x64)
Memory used 534,456k (± 0.01%) 639,899k (± 0.00%) +105,443k (+19.73%) 639,841k 639,974k
Parse Time 2.57s (± 0.57%) 2.58s (± 0.32%) +0.00s (+ 0.04%) 2.56s 2.59s
Bind Time 1.15s (± 0.56%) 1.16s (± 0.71%) +0.01s (+ 0.43%) 1.15s 1.18s
Check Time 1.47s (± 0.23%) 4.47s (± 0.44%) 🔻+3.00s (+203.46%) 4.43s 4.51s
Emit Time 0.07s (± 0.00%) 0.07s (± 3.14%) +0.00s (+ 1.43%) 0.07s 0.08s
Total Time 5.28s (± 0.29%) 8.28s (± 0.29%) 🔻+3.00s (+56.88%) 8.23s 8.33s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory5 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 45628 10
Baseline main 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/120377/artifacts?artifactName=tgz&fileId=30D5EC3BF9FD87861ED6C80354041E0086256D68AECB7803F51F754554A5659F02&fileName=/typescript-4.7.0-insiders.20220217.tgz"
    }
}

and then running npm install.

@ahejlsberg
Copy link
Member Author

Yikes, the xstate performance test is heavily impacted by this (+200%). Definitely not ready to go yet.

@Andarist
Copy link
Contributor

Hah, I'm actually XState maintainer 😅 In a way - I think that our types need a solid overhaul anyway. I wonder if there is anything in particular that we could take into consideration when refactoring, are there any particular things that we could try to avoid. While... we are flattered to be included in your perf test suite 😉 it's also a good sign that maybe we are overcomplicating things for the typechecker.

Some recent changes to our types are in particular quite crazy (those designed to work with the typegen and have very unusual patterns used in them to "stitch" types together). My sincere hope is that this particular perf problem is not related to this part of the types as I took a loooot of time to get them working. Could you tell me against which version of XState are you running this benchmark? It would be useful for such information to be included somewhere in the result - as far as I can tell it's not in the comment of the bot nor in the attached benchmark file.

When it comes to the variance itself - I'm pretty sure our types "get it wrong" (from the user perspective). While I understand the concept of variance and can "compute" variance type in simple cases, I have no idea how I should think about it with such complicated types as ours, with a lot of layers, a lot of generics etc. Are there any resources/comments from the past that could help me understand this? Are there any tricks that could help TS to determine the variance type "quicker"?

On a more positive note - I've tested this build and it seems to fix my minimal repro case reported here and it also fixes the issue in our repo from which I've distilled this minimal repro. 🎉

@RyanCavanaugh
Copy link
Member

@Andarist Thanks for taking such an interest in this!

Our current instructions for profiling compilation times are at https://github.com/microsoft/TypeScript/wiki/Performance-Tracing and there are some other resources at https://github.com/microsoft/TypeScript/wiki/Performance

The benchmarks run against whatever is currently checked into GitHub. We run against latest to avoid getting stale versions of projects which might not be taking advantage of newer language features.

How to make a project build faster in general is outside the scope of this comment box, but I'd be happy to talk about it in a separate issue after you've run tracing and identified some hotspots.

@Andarist
Copy link
Contributor

@RyanCavanaugh would you recommend performing this profiling using the latest TS or using the build from this PR? I'm unsure what's better from your perspective - for us to attempt to recognize current issues~ or the stuff specifically related to this PR?

The benchmarks run against whatever is currently checked into GitHub. We run against latest to avoid getting stale versions of projects which might not be taking advantage of newer language features.

Thanks, that's good to know - I would recommend adding information somewhere about the commit against which those profiling sessions were executed. It would ensure that we can always investigate exactly the same builds etc when any issues are recognized by this automatic benchmarking.

How to make a project build faster in general is outside the scope of this comment box, but I'd be happy to talk about it in a separate issue after you've run tracing and identified some hotspots.

Thanks, I will certainly come back asking questions 🤣 I'll try to book some time in our next cycle to poke around this

@Andarist
Copy link
Contributor

I might also have found a problem with this PR unless the goal of this PR is not to handle all of the possible cases. Are perhaps still situations when you might bail out from the process and assume that some types are assignable when they shouldn't?

As far as I can tell the result of the spawn should not be accepted within the createMachine call at the bottom of this screenshot. I've performed various checks above this situation to confirm subtyping rules etc

Screenshot 2022-02-24 at 11 26 55

I can try to prepare a reduced test case but since that's sometimes up to a day of work I'd like to confirm with you that it's worth it.

The issue can be observed on commit f256378e6 in xstate repo (this is a note for my own reference)

@ahejlsberg
Copy link
Member Author

Closing in favor of #48080.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Check order dependence with mutually-recursive non-unary generics
7 participants