Skip to content

Conversation

@ahejlsberg
Copy link
Member

This PR cleans up the ObjectFlags enum. Specifically, it organizes the flags such that bit positions are reused to have different meanings in different types. This frees up several bit positions and ensures that no flags use bit positions 30 and above. We previously had a flag with the value 1 << 30, the use of which adversely impacted performance because the VM boxes values in that range.

@Pokute
Copy link

Pokute commented Apr 19, 2021

Does this break the API? Previously internal IsGenericObjectTypeComputed is visible as ContainsSpread for API, but the users never had to check the typeFlags. This could result in something like a naive AST explorer displaying a union having spread. Pretty rare, but possible.

@sandersn
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 19, 2021

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

Update: The results are in!

@ahejlsberg
Copy link
Member Author

Does this break the API?

Yes, in theory it is a breaking change because a couple of visible flags now require a check of TypeFlags first. That said, ContainsSpread and ObjectRestType are pretty esoteric flags, and I'm almost inclined to just make them private.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43732

Metric master 43732 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 344,960k (± 0.02%) 344,913k (± 0.03%) -48k (- 0.01%) 344,785k 345,202k
Parse Time 1.95s (± 0.58%) 1.95s (± 0.55%) -0.00s (- 0.21%) 1.93s 1.97s
Bind Time 0.84s (± 0.44%) 0.84s (± 0.62%) +0.00s (+ 0.36%) 0.83s 0.85s
Check Time 5.24s (± 0.40%) 5.21s (± 0.50%) -0.03s (- 0.57%) 5.17s 5.28s
Emit Time 5.92s (± 0.51%) 5.92s (± 1.01%) +0.00s (+ 0.03%) 5.84s 6.10s
Total Time 13.95s (± 0.37%) 13.92s (± 0.55%) -0.03s (- 0.22%) 13.78s 14.08s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,159k (± 0.04%) 203,093k (± 0.04%) -66k (- 0.03%) 202,959k 203,346k
Parse Time 0.79s (± 0.95%) 0.79s (± 1.04%) 0.00s ( 0.00%) 0.77s 0.81s
Bind Time 0.53s (± 1.13%) 0.53s (± 1.13%) 0.00s ( 0.00%) 0.51s 0.54s
Check Time 7.58s (± 0.89%) 7.52s (± 0.52%) -0.06s (- 0.75%) 7.46s 7.63s
Emit Time 2.51s (± 1.16%) 2.49s (± 1.02%) -0.02s (- 0.87%) 2.42s 2.54s
Total Time 11.41s (± 0.83%) 11.33s (± 0.53%) -0.08s (- 0.68%) 11.24s 11.49s
Monaco - node (v10.16.3, x64)
Memory used 342,644k (± 0.02%) 342,589k (± 0.02%) -56k (- 0.02%) 342,475k 342,731k
Parse Time 1.57s (± 0.48%) 1.56s (± 0.64%) -0.00s (- 0.13%) 1.54s 1.58s
Bind Time 0.74s (± 0.66%) 0.74s (± 0.64%) -0.00s (- 0.13%) 0.73s 0.75s
Check Time 5.33s (± 0.74%) 5.30s (± 0.26%) -0.02s (- 0.45%) 5.27s 5.33s
Emit Time 3.02s (± 1.01%) 3.03s (± 0.63%) +0.00s (+ 0.10%) 2.96s 3.05s
Total Time 10.66s (± 0.47%) 10.63s (± 0.29%) -0.03s (- 0.29%) 10.56s 10.69s
TFS - node (v10.16.3, x64)
Memory used 304,156k (± 0.01%) 304,213k (± 0.02%) +57k (+ 0.02%) 304,005k 304,326k
Parse Time 1.22s (± 0.56%) 1.22s (± 0.72%) +0.00s (+ 0.16%) 1.19s 1.24s
Bind Time 0.71s (± 0.87%) 0.71s (± 0.70%) -0.00s (- 0.42%) 0.70s 0.72s
Check Time 4.75s (± 0.46%) 4.76s (± 0.43%) +0.01s (+ 0.21%) 4.69s 4.80s
Emit Time 3.19s (± 0.88%) 3.17s (± 0.93%) -0.02s (- 0.50%) 3.10s 3.22s
Total Time 9.86s (± 0.38%) 9.85s (± 0.46%) -0.01s (- 0.06%) 9.73s 9.93s
material-ui - node (v10.16.3, x64)
Memory used 465,277k (± 0.01%) 465,172k (± 0.02%) -106k (- 0.02%) 464,927k 465,306k
Parse Time 2.02s (± 0.67%) 2.01s (± 0.48%) -0.01s (- 0.35%) 1.98s 2.03s
Bind Time 0.66s (± 1.32%) 0.66s (± 1.28%) +0.00s (+ 0.15%) 0.64s 0.68s
Check Time 14.57s (± 0.90%) 14.45s (± 0.66%) -0.12s (- 0.83%) 14.29s 14.71s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 17.25s (± 0.83%) 17.13s (± 0.60%) -0.13s (- 0.72%) 16.95s 17.41s
Angular - node (v12.1.0, x64)
Memory used 322,637k (± 0.02%) 322,646k (± 0.03%) +8k (+ 0.00%) 322,364k 322,794k
Parse Time 1.95s (± 0.83%) 1.93s (± 0.47%) -0.02s (- 1.08%) 1.90s 1.95s
Bind Time 0.82s (± 0.73%) 0.82s (± 0.84%) 0.00s ( 0.00%) 0.80s 0.83s
Check Time 5.11s (± 0.42%) 5.10s (± 0.35%) -0.01s (- 0.18%) 5.06s 5.13s
Emit Time 6.15s (± 0.90%) 6.11s (± 0.56%) -0.03s (- 0.52%) 6.05s 6.20s
Total Time 14.02s (± 0.51%) 13.96s (± 0.39%) -0.06s (- 0.45%) 13.82s 14.07s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,161k (± 0.14%) 190,270k (± 0.22%) +109k (+ 0.06%) 188,899k 190,812k
Parse Time 0.77s (± 0.52%) 0.77s (± 0.52%) 0.00s ( 0.00%) 0.76s 0.78s
Bind Time 0.53s (± 0.84%) 0.52s (± 0.65%) -0.01s (- 0.95%) 0.52s 0.53s
Check Time 7.04s (± 0.65%) 7.00s (± 0.97%) -0.04s (- 0.53%) 6.89s 7.24s
Emit Time 2.48s (± 1.31%) 2.48s (± 1.23%) -0.01s (- 0.32%) 2.42s 2.54s
Total Time 10.82s (± 0.37%) 10.77s (± 0.64%) -0.05s (- 0.46%) 10.66s 10.98s
Monaco - node (v12.1.0, x64)
Memory used 324,913k (± 0.06%) 325,028k (± 0.02%) +115k (+ 0.04%) 324,875k 325,163k
Parse Time 1.54s (± 1.14%) 1.53s (± 0.72%) -0.01s (- 0.52%) 1.50s 1.56s
Bind Time 0.72s (± 0.86%) 0.72s (± 0.66%) +0.00s (+ 0.28%) 0.71s 0.73s
Check Time 5.18s (± 0.41%) 5.15s (± 0.54%) -0.03s (- 0.56%) 5.09s 5.23s
Emit Time 3.10s (± 0.88%) 3.07s (± 0.87%) -0.03s (- 0.90%) 3.00s 3.12s
Total Time 10.54s (± 0.42%) 10.48s (± 0.35%) -0.06s (- 0.59%) 10.41s 10.55s
TFS - node (v12.1.0, x64)
Memory used 288,655k (± 0.02%) 288,637k (± 0.02%) -17k (- 0.01%) 288,489k 288,802k
Parse Time 1.22s (± 0.68%) 1.21s (± 0.92%) -0.01s (- 0.74%) 1.19s 1.25s
Bind Time 0.69s (± 0.89%) 0.69s (± 0.68%) -0.00s (- 0.14%) 0.68s 0.70s
Check Time 4.68s (± 0.34%) 4.66s (± 0.47%) -0.02s (- 0.45%) 4.59s 4.70s
Emit Time 3.24s (± 1.60%) 3.19s (± 0.88%) -0.05s (- 1.42%) 3.14s 3.27s
Total Time 9.83s (± 0.59%) 9.76s (± 0.50%) -0.07s (- 0.76%) 9.62s 9.84s
material-ui - node (v12.1.0, x64)
Memory used 443,186k (± 0.07%) 443,292k (± 0.05%) +105k (+ 0.02%) 442,424k 443,532k
Parse Time 2.04s (± 0.71%) 2.03s (± 0.46%) -0.01s (- 0.39%) 2.01s 2.05s
Bind Time 0.64s (± 0.96%) 0.65s (± 1.18%) +0.00s (+ 0.62%) 0.63s 0.66s
Check Time 13.14s (± 1.16%) 13.03s (± 0.66%) -0.11s (- 0.82%) 12.87s 13.26s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.82s (± 0.95%) 15.71s (± 0.57%) -0.11s (- 0.69%) 15.53s 15.93s
Angular - node (v14.15.1, x64)
Memory used 321,255k (± 0.01%) 321,278k (± 0.00%) +23k (+ 0.01%) 321,254k 321,308k
Parse Time 1.93s (± 0.64%) 1.94s (± 0.86%) +0.01s (+ 0.31%) 1.91s 1.97s
Bind Time 0.87s (± 0.51%) 0.86s (± 0.57%) -0.00s (- 0.46%) 0.86s 0.88s
Check Time 5.13s (± 0.54%) 5.15s (± 0.55%) +0.02s (+ 0.39%) 5.10s 5.22s
Emit Time 6.22s (± 0.77%) 6.22s (± 0.63%) +0.01s (+ 0.13%) 6.17s 6.33s
Total Time 14.15s (± 0.49%) 14.18s (± 0.37%) +0.03s (+ 0.23%) 14.05s 14.26s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,572k (± 0.38%) 189,552k (± 0.37%) -20k (- 0.01%) 189,202k 192,410k
Parse Time 0.80s (± 0.61%) 0.80s (± 0.28%) -0.00s (- 0.37%) 0.80s 0.81s
Bind Time 0.56s (± 1.10%) 0.56s (± 0.53%) -0.00s (- 0.18%) 0.55s 0.56s
Check Time 7.14s (± 0.52%) 7.11s (± 0.62%) -0.03s (- 0.36%) 7.04s 7.22s
Emit Time 2.51s (± 0.76%) 2.49s (± 0.81%) -0.02s (- 0.64%) 2.44s 2.53s
Total Time 11.00s (± 0.45%) 10.96s (± 0.48%) -0.04s (- 0.40%) 10.88s 11.09s
Monaco - node (v14.15.1, x64)
Memory used 324,028k (± 0.01%) 324,051k (± 0.01%) +23k (+ 0.01%) 324,005k 324,089k
Parse Time 1.58s (± 0.95%) 1.57s (± 0.79%) -0.01s (- 0.51%) 1.55s 1.61s
Bind Time 0.75s (± 0.80%) 0.75s (± 0.66%) +0.00s (+ 0.13%) 0.74s 0.76s
Check Time 5.12s (± 0.55%) 5.12s (± 0.34%) -0.00s (- 0.08%) 5.07s 5.15s
Emit Time 3.12s (± 0.50%) 3.14s (± 0.81%) +0.01s (+ 0.35%) 3.08s 3.18s
Total Time 10.57s (± 0.47%) 10.57s (± 0.40%) -0.00s (- 0.03%) 10.48s 10.64s
TFS - node (v14.15.1, x64)
Memory used 287,633k (± 0.01%) 287,633k (± 0.01%) -0k (- 0.00%) 287,582k 287,690k
Parse Time 1.27s (± 1.10%) 1.27s (± 0.83%) -0.00s (- 0.16%) 1.24s 1.29s
Bind Time 0.71s (± 0.56%) 0.72s (± 0.51%) +0.00s (+ 0.70%) 0.71s 0.72s
Check Time 4.72s (± 0.41%) 4.72s (± 0.45%) -0.01s (- 0.13%) 4.67s 4.76s
Emit Time 3.30s (± 0.51%) 3.29s (± 0.76%) -0.01s (- 0.18%) 3.24s 3.34s
Total Time 10.01s (± 0.29%) 10.00s (± 0.41%) -0.01s (- 0.12%) 9.92s 10.10s
material-ui - node (v14.15.1, x64)
Memory used 441,460k (± 0.06%) 441,569k (± 0.00%) +109k (+ 0.02%) 441,543k 441,610k
Parse Time 2.10s (± 0.77%) 2.10s (± 0.69%) -0.00s (- 0.14%) 2.06s 2.13s
Bind Time 0.70s (± 0.63%) 0.70s (± 0.71%) -0.01s (- 0.85%) 0.69s 0.71s
Check Time 13.23s (± 0.64%) 13.26s (± 0.74%) +0.03s (+ 0.26%) 13.06s 13.47s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.03s (± 0.56%) 16.06s (± 0.65%) +0.03s (+ 0.19%) 15.84s 16.28s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory8 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 43732 10
Baseline master 10

Developer Information:

Download Benchmark

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

I'm honestly surprised there wasn't anywhere we had to introduce a TypeFlags check.

@sandersn
Copy link
Member

I was curious so I ran the perf tests; this doesn't make a performance difference for x64, at least on any of the versions of node we test on.

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Apr 19, 2021

@sandersn Yeah, the offending flag is ObjectFlags.IsClassInstanceClone which I think is rarely used. But out of range flags definitely do affect performance, we've seen and measured that previously.

@ahejlsberg ahejlsberg merged commit 52ec8ce into master Apr 19, 2021
@ahejlsberg ahejlsberg deleted the fixObjectFlags branch April 19, 2021 22:33
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

6 participants