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

Refactor node factory API, use node factory in parser #35282

Merged
merged 20 commits into from
Jun 16, 2020
Merged

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Nov 22, 2019

This overhauls our node factory API to provide the following benefits:

  • Allows us to leverage the factory API from within the parser.
    • This is intended to help us ensure that the property layout of each kind of Node is stable between the parser, checker, and transformers to reduce polymorphism, as well as to provide a "single source of truth" with respect to how nodes are created.
  • Allows us to streamline transform flag aggregation into node creation.
    • This allows us to remove transform flag logic from binder.ts and transformer.ts and ensures that transform flags will always be correctly aggregated during transformations.
  • Extracts our auto-parenthesization logic out of the node factories.
    • This allows us to use the new node factories in the parser without the undue overhead incurred by the parenthesizer rules.
  • Allows us to deprecate older node factory APIs and reduce node factory overloads.

In the future, this will also allow us to better isolate which transformer was responsible for creating nodes, as well as to possibly leverage transformers outside of the emit pipeline.

As part of these changes, all of the existing create* and update* factory functions in the ts namespace are being moved to a NodeFactory object that can be created via the internal createNodeFactory function. Authors of transformers can access the NodeFactory associated with their transformation via the TransformationContext provided to their transformer:

import * as ts from "typescript";
function myTransformer(context: ts.TransformationContext) {
  // old: createIdentifier("foo");

  // new (option 1):
  const { factory } = context;
  factory.createIdentifier("foo");

  // new (option 2):
  const { factory: { createIdentifier } } = context;
  createIdentifier("foo"); // same as old
}

In addition, the ts.factory object is a singleton NodeFactory instance, which can be used to create synthetic nodes outside of a transformer.

So as not to break compatibility with older API consumers, the existing create* and update* factory functions will also be available to consumers of the TypeScript language service and the TS Server API. However, these functions are considered deprecated, and will be phased out using the following (tentative) plan:

  • 4.0 - Existing factory functions are marked with a @deprecated JSDoc comment and are no longer used by TypeScript internals.
  • 4.1 (?) - The first time a deprecated factory function is called, the Language Service will attempt to write a deprecation warning message (depending on the host and whether a suitable console.log-like logger is available).
  • 4.2 (?) - Whenever a deprecated factory function is called, an exception will be thrown.
  • 4.3 (?) - Deprecated factory functions will be removed.

Remaining TODO items:

  • Consider renaming concise functions like createParen to a more expressive (and less ambiguous) name such as createParenthesizedExpression.
  • Consider making most properties of nodes readonly, as one goal is to treat a TypeScript AST as immutable (and should be "changed" via visitors).
  • Verify performance of parser use of new API.

@rbuckton
Copy link
Member Author

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 22, 2019

Heya @rbuckton, I've started to run the perf test suite on this PR at 922ab41. You can monitor the build here. It should now contribute to this PR's status checks.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..35282

Metric master 35282 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 354,711k (± 0.02%) 334,758k (± 0.02%) -19,953k (- 5.63%) 334,530k 334,897k
Parse Time 1.63s (± 0.71%) 1.90s (± 0.41%) +0.27s (+16.91%) 1.88s 1.92s
Bind Time 0.86s (± 0.67%) 0.75s (± 1.21%) -0.11s (-12.98%) 0.74s 0.77s
Check Time 4.53s (± 0.53%) 4.46s (± 0.55%) -0.07s (- 1.44%) 4.38s 4.50s
Emit Time 5.27s (± 0.59%) 5.08s (± 0.55%) -0.19s (- 3.60%) 5.04s 5.15s
Total Time 12.29s (± 0.42%) 12.20s (± 0.27%) -0.10s (- 0.77%) 12.13s 12.28s
Monaco - node (v10.16.3, x64)
Memory used 365,915k (± 0.01%) 340,571k (± 0.03%) -25,344k (- 6.93%) 340,328k 340,866k
Parse Time 1.27s (± 0.51%) 1.49s (± 0.60%) +0.23s (+17.90%) 1.47s 1.51s
Bind Time 0.76s (± 0.79%) 0.65s (± 0.51%) -0.10s (-13.91%) 0.64s 0.66s
Check Time 4.67s (± 0.26%) 4.61s (± 0.41%) -0.06s (- 1.35%) 4.57s 4.67s
Emit Time 2.98s (± 1.47%) 2.78s (± 0.57%) -0.20s (- 6.72%) 2.74s 2.81s
Total Time 9.67s (± 0.47%) 9.53s (± 0.30%) -0.14s (- 1.49%) 9.46s 9.58s
TFS - node (v10.16.3, x64)
Memory used 321,656k (± 0.02%) 299,620k (± 0.02%) -22,036k (- 6.85%) 299,542k 299,753k
Parse Time 0.97s (± 0.87%) 1.19s (± 0.69%) +0.22s (+22.25%) 1.17s 1.21s
Bind Time 0.72s (± 1.03%) 0.60s (± 1.11%) -0.12s (-16.67%) 0.59s 0.62s
Check Time 4.14s (± 0.53%) 4.08s (± 0.36%) -0.06s (- 1.45%) 4.04s 4.10s
Emit Time 3.07s (± 0.85%) 2.78s (± 0.76%) -0.29s (- 9.50%) 2.72s 2.82s
Total Time 8.91s (± 0.58%) 8.65s (± 0.30%) -0.25s (- 2.86%) 8.59s 8.70s
Angular - node (v12.1.0, x64)
Memory used 330,312k (± 0.04%) 312,079k (± 0.02%) -18,232k (- 5.52%) 311,933k 312,196k
Parse Time 1.58s (± 0.74%) 1.86s (± 0.83%) +0.28s (+17.92%) 1.83s 1.89s
Bind Time 0.84s (± 0.44%) 0.72s (± 0.80%) -0.12s (-14.44%) 0.71s 0.74s
Check Time 4.45s (± 0.58%) 4.36s (± 0.66%) -0.10s (- 2.16%) 4.31s 4.42s
Emit Time 5.50s (± 1.08%) 5.30s (± 0.58%) -0.20s (- 3.65%) 5.25s 5.40s
Total Time 12.38s (± 0.63%) 12.25s (± 0.40%) -0.14s (- 1.10%) 12.15s 12.35s
Monaco - node (v12.1.0, x64)
Memory used 345,639k (± 0.01%) 322,985k (± 0.05%) -22,655k (- 6.55%) 322,410k 323,132k
Parse Time 1.23s (± 0.59%) 1.47s (± 0.82%) +0.24s (+19.64%) 1.45s 1.50s
Bind Time 0.73s (± 0.68%) 0.61s (± 0.65%) -0.11s (-15.84%) 0.60s 0.62s
Check Time 4.49s (± 0.39%) 4.49s (± 0.45%) +0.00s (+ 0.04%) 4.44s 4.54s
Emit Time 3.02s (± 0.79%) 2.86s (± 0.53%) -0.17s (- 5.49%) 2.81s 2.89s
Total Time 9.47s (± 0.41%) 9.43s (± 0.42%) -0.03s (- 0.37%) 9.32s 9.52s
TFS - node (v12.1.0, x64)
Memory used 304,040k (± 0.01%) 284,044k (± 0.01%) -19,995k (- 6.58%) 283,980k 284,106k
Parse Time 0.95s (± 0.78%) 1.21s (± 1.14%) +0.25s (+26.55%) 1.18s 1.24s
Bind Time 0.68s (± 1.00%) 0.57s (± 0.78%) -0.12s (-16.96%) 0.56s 0.58s
Check Time 4.06s (± 0.49%) 4.04s (± 0.51%) -0.02s (- 0.52%) 4.00s 4.08s
Emit Time 3.11s (± 1.15%) 2.90s (± 0.65%) -0.21s (- 6.75%) 2.86s 2.95s
Total Time 8.81s (± 0.43%) 8.71s (± 0.41%) -0.09s (- 1.08%) 8.65s 8.78s
Angular - node (v8.9.0, x64)
Memory used 349,598k (± 0.01%) 330,993k (± 0.01%) -18,605k (- 5.32%) 330,940k 331,111k
Parse Time 2.11s (± 0.41%) 2.41s (± 0.53%) +0.30s (+14.42%) 2.38s 2.44s
Bind Time 0.91s (± 0.55%) 0.79s (± 0.71%) -0.12s (-12.93%) 0.78s 0.80s
Check Time 5.31s (± 0.31%) 5.22s (± 0.56%) -0.09s (- 1.75%) 5.16s 5.30s
Emit Time 6.31s (± 0.81%) 6.08s (± 1.22%) -0.23s (- 3.68%) 5.88s 6.23s
Total Time 14.63s (± 0.35%) 14.49s (± 0.72%) -0.14s (- 0.94%) 14.24s 14.69s
Monaco - node (v8.9.0, x64)
Memory used 363,743k (± 0.01%) 341,050k (± 0.01%) -22,694k (- 6.24%) 340,920k 341,126k
Parse Time 1.56s (± 0.52%) 1.80s (± 0.61%) +0.24s (+15.16%) 1.78s 1.83s
Bind Time 0.93s (± 0.75%) 0.84s (± 0.57%) -0.09s (- 9.90%) 0.83s 0.85s
Check Time 5.56s (± 0.64%) 5.28s (± 0.41%) -0.27s (- 4.95%) 5.23s 5.32s
Emit Time 3.05s (± 0.67%) 3.30s (± 0.76%) +0.24s (+ 7.86%) 3.23s 3.35s
Total Time 11.10s (± 0.51%) 11.21s (± 0.37%) +0.10s (+ 0.95%) 11.15s 11.30s
TFS - node (v8.9.0, x64)
Memory used 320,632k (± 0.01%) 300,490k (± 0.01%) -20,142k (- 6.28%) 300,422k 300,584k
Parse Time 1.27s (± 0.53%) 1.51s (± 0.60%) +0.24s (+18.54%) 1.49s 1.53s
Bind Time 0.74s (± 0.54%) 0.62s (± 0.55%) -0.12s (-16.73%) 0.61s 0.62s
Check Time 4.76s (± 0.43%) 4.69s (± 0.46%) -0.07s (- 1.51%) 4.66s 4.75s
Emit Time 3.22s (± 1.09%) 3.01s (± 0.65%) -0.21s (- 6.46%) 2.97s 3.06s
Total Time 10.00s (± 0.49%) 9.83s (± 0.40%) -0.17s (- 1.71%) 9.74s 9.91s
Angular - node (v8.9.0, x86)
Memory used 198,499k (± 0.02%) 189,508k (± 0.03%) -8,991k (- 4.53%) 189,394k 189,666k
Parse Time 2.03s (± 0.58%) 2.34s (± 0.85%) +0.31s (+15.26%) 2.30s 2.38s
Bind Time 1.04s (± 1.21%) 0.93s (± 0.73%) -0.11s (-10.28%) 0.93s 0.96s
Check Time 4.82s (± 0.72%) 4.76s (± 0.41%) -0.06s (- 1.20%) 4.72s 4.80s
Emit Time 6.11s (± 0.66%) 5.83s (± 1.23%) -0.28s (- 4.54%) 5.65s 6.03s
Total Time 14.00s (± 0.39%) 13.86s (± 0.59%) -0.13s (- 0.96%) 13.64s 14.10s
Monaco - node (v8.9.0, x86)
Memory used 203,768k (± 0.02%) 192,720k (± 0.02%) -11,049k (- 5.42%) 192,650k 192,860k
Parse Time 1.61s (± 0.44%) 1.86s (± 1.08%) +0.25s (+15.48%) 1.82s 1.91s
Bind Time 0.75s (± 0.99%) 0.66s (± 1.38%) -0.09s (-12.48%) 0.65s 0.68s
Check Time 5.42s (± 0.43%) 5.37s (± 0.48%) -0.05s (- 0.96%) 5.31s 5.42s
Emit Time 2.88s (± 0.42%) 2.70s (± 0.82%) -0.18s (- 6.21%) 2.66s 2.75s
Total Time 10.66s (± 0.25%) 10.59s (± 0.51%) -0.07s (- 0.70%) 10.46s 10.70s
TFS - node (v8.9.0, x86)
Memory used 180,595k (± 0.02%) 170,821k (± 0.02%) -9,774k (- 5.41%) 170,716k 170,885k
Parse Time 1.30s (± 0.38%) 1.55s (± 1.18%) +0.24s (+18.79%) 1.52s 1.60s
Bind Time 0.69s (± 0.53%) 0.59s (± 0.84%) -0.11s (-15.68%) 0.58s 0.60s
Check Time 4.48s (± 0.54%) 4.44s (± 0.80%) -0.04s (- 0.83%) 4.38s 4.54s
Emit Time 2.97s (± 0.57%) 2.79s (± 0.96%) -0.18s (- 6.07%) 2.72s 2.84s
Total Time 9.44s (± 0.36%) 9.37s (± 0.65%) -0.08s (- 0.82%) 9.25s 9.52s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory7 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
Benchmark Name Iterations
Current 35282 10
Baseline master 10

@rbuckton
Copy link
Member Author

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 13, 2019

Heya @rbuckton, I've started to run the perf test suite on this PR at ae7c638. You can monitor the build here. It should now contribute to this PR's status checks.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..35282

Metric master 35282 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 354,603k (± 0.01%) 334,788k (± 0.02%) -19,815k (- 5.59%) 334,590k 334,926k
Parse Time 1.63s (± 0.63%) 1.98s (± 0.59%) +0.35s (+21.24%) 1.95s 2.00s
Bind Time 0.86s (± 0.72%) 0.78s (± 0.64%) -0.09s (- 9.99%) 0.77s 0.79s
Check Time 4.53s (± 1.61%) 4.45s (± 0.29%) -0.08s (- 1.88%) 4.42s 4.48s
Emit Time 5.26s (± 1.39%) 5.13s (± 1.21%) -0.13s (- 2.55%) 5.00s 5.33s
Total Time 12.29s (± 1.20%) 12.32s (± 0.53%) +0.04s (+ 0.28%) 12.15s 12.51s
Monaco - node (v10.16.3, x64)
Memory used 366,191k (± 0.02%) 340,557k (± 0.02%) -25,634k (- 7.00%) 340,339k 340,676k
Parse Time 1.27s (± 1.04%) 1.57s (± 0.53%) +0.30s (+23.42%) 1.55s 1.59s
Bind Time 0.75s (± 0.59%) 0.66s (± 1.21%) -0.09s (-11.97%) 0.65s 0.68s
Check Time 4.65s (± 0.43%) 4.61s (± 0.59%) -0.04s (- 0.97%) 4.54s 4.66s
Emit Time 2.93s (± 0.70%) 2.80s (± 0.94%) -0.13s (- 4.27%) 2.75s 2.88s
Total Time 9.61s (± 0.48%) 9.64s (± 0.45%) +0.04s (+ 0.39%) 9.56s 9.74s
TFS - node (v10.16.3, x64)
Memory used 322,141k (± 0.03%) 299,598k (± 0.03%) -22,543k (- 7.00%) 299,317k 299,745k
Parse Time 0.96s (± 0.78%) 1.24s (± 0.66%) +0.28s (+29.26%) 1.22s 1.25s
Bind Time 0.73s (± 0.92%) 0.61s (± 0.73%) -0.11s (-15.82%) 0.61s 0.63s
Check Time 4.14s (± 0.71%) 4.10s (± 0.43%) -0.04s (- 0.94%) 4.06s 4.14s
Emit Time 3.02s (± 1.00%) 2.82s (± 0.80%) -0.20s (- 6.69%) 2.74s 2.86s
Total Time 8.84s (± 0.53%) 8.77s (± 0.31%) -0.08s (- 0.87%) 8.70s 8.82s
Angular - node (v12.1.0, x64)
Memory used 330,237k (± 0.09%) 312,099k (± 0.02%) -18,139k (- 5.49%) 311,937k 312,258k
Parse Time 1.56s (± 0.47%) 1.93s (± 0.42%) +0.37s (+23.75%) 1.92s 1.95s
Bind Time 0.84s (± 0.57%) 0.74s (± 0.78%) -0.10s (-11.59%) 0.73s 0.75s
Check Time 4.44s (± 0.57%) 4.36s (± 0.54%) -0.07s (- 1.67%) 4.30s 4.42s
Emit Time 5.46s (± 1.22%) 5.33s (± 0.52%) -0.13s (- 2.38%) 5.26s 5.39s
Total Time 12.29s (± 0.65%) 12.36s (± 0.40%) +0.07s (+ 0.54%) 12.26s 12.45s
Monaco - node (v12.1.0, x64)
Memory used 345,874k (± 0.02%) 322,943k (± 0.02%) -22,931k (- 6.63%) 322,755k 323,037k
Parse Time 1.23s (± 0.48%) 1.54s (± 0.84%) +0.31s (+25.37%) 1.51s 1.56s
Bind Time 0.72s (± 0.97%) 0.63s (± 0.47%) -0.09s (-12.66%) 0.62s 0.63s
Check Time 4.50s (± 0.53%) 4.46s (± 0.53%) -0.05s (- 1.00%) 4.39s 4.51s
Emit Time 2.99s (± 1.23%) 2.90s (± 1.20%) -0.09s (- 3.08%) 2.85s 3.01s
Total Time 9.44s (± 0.55%) 9.53s (± 0.58%) +0.09s (+ 0.93%) 9.38s 9.63s
TFS - node (v12.1.0, x64)
Memory used 304,436k (± 0.02%) 283,915k (± 0.02%) -20,522k (- 6.74%) 283,716k 284,049k
Parse Time 0.94s (± 0.69%) 1.25s (± 1.03%) +0.32s (+33.80%) 1.23s 1.28s
Bind Time 0.68s (± 0.54%) 0.58s (± 1.11%) -0.09s (-13.91%) 0.57s 0.60s
Check Time 4.06s (± 0.40%) 4.03s (± 0.49%) -0.03s (- 0.76%) 3.98s 4.07s
Emit Time 3.08s (± 1.15%) 2.93s (± 1.09%) -0.15s (- 4.88%) 2.88s 3.02s
Total Time 8.75s (± 0.45%) 8.79s (± 0.48%) +0.04s (+ 0.41%) 8.72s 8.92s
Angular - node (v8.9.0, x64)
Memory used 349,435k (± 0.01%) 330,992k (± 0.02%) -18,444k (- 5.28%) 330,896k 331,144k
Parse Time 2.10s (± 0.36%) 2.47s (± 0.70%) +0.37s (+17.49%) 2.44s 2.52s
Bind Time 0.92s (± 0.75%) 0.81s (± 0.71%) -0.10s (-11.48%) 0.79s 0.82s
Check Time 5.32s (± 0.86%) 5.26s (± 0.38%) -0.05s (- 1.02%) 5.22s 5.31s
Emit Time 6.23s (± 0.53%) 6.10s (± 1.15%) -0.13s (- 2.07%) 5.95s 6.22s
Total Time 14.57s (± 0.41%) 14.64s (± 0.53%) +0.08s (+ 0.54%) 14.46s 14.77s
Monaco - node (v8.9.0, x64)
Memory used 364,024k (± 0.01%) 341,085k (± 0.01%) -22,939k (- 6.30%) 341,020k 341,147k
Parse Time 1.57s (± 0.49%) 1.85s (± 0.35%) +0.29s (+18.34%) 1.84s 1.87s
Bind Time 0.93s (± 1.15%) 0.84s (± 0.44%) -0.08s (- 8.75%) 0.84s 0.85s
Check Time 5.51s (± 1.64%) 5.28s (± 0.29%) -0.24s (- 4.33%) 5.24s 5.31s
Emit Time 3.16s (± 4.52%) 3.32s (± 0.75%) +0.16s (+ 5.06%) 3.25s 3.37s
Total Time 11.17s (± 0.84%) 11.29s (± 0.25%) +0.13s (+ 1.16%) 11.23s 11.35s
TFS - node (v8.9.0, x64)
Memory used 321,128k (± 0.02%) 300,547k (± 0.01%) -20,581k (- 6.41%) 300,454k 300,613k
Parse Time 1.27s (± 0.37%) 1.56s (± 0.40%) +0.29s (+22.76%) 1.55s 1.57s
Bind Time 0.74s (± 0.65%) 0.63s (± 0.53%) -0.11s (-14.52%) 0.62s 0.64s
Check Time 4.74s (± 0.64%) 4.70s (± 0.73%) -0.04s (- 0.87%) 4.61s 4.79s
Emit Time 3.20s (± 0.95%) 3.01s (± 0.61%) -0.19s (- 5.91%) 2.96s 3.04s
Total Time 9.95s (± 0.52%) 9.89s (± 0.51%) -0.05s (- 0.50%) 9.74s 10.03s
Angular - node (v8.9.0, x86)
Memory used 198,438k (± 0.02%) 189,538k (± 0.03%) -8,900k (- 4.49%) 189,396k 189,664k
Parse Time 2.03s (± 1.10%) 2.38s (± 0.44%) +0.35s (+17.09%) 2.36s 2.41s
Bind Time 1.02s (± 0.85%) 0.95s (± 0.98%) -0.07s (- 7.24%) 0.92s 0.96s
Check Time 4.84s (± 0.52%) 4.72s (± 0.95%) -0.12s (- 2.38%) 4.65s 4.83s
Emit Time 6.09s (± 1.36%) 5.88s (± 0.40%) -0.21s (- 3.46%) 5.83s 5.93s
Total Time 13.99s (± 0.66%) 13.93s (± 0.37%) -0.05s (- 0.39%) 13.81s 14.07s
Monaco - node (v8.9.0, x86)
Memory used 203,977k (± 0.02%) 192,792k (± 0.02%) -11,185k (- 5.48%) 192,694k 192,877k
Parse Time 1.61s (± 0.73%) 1.89s (± 0.96%) +0.28s (+17.28%) 1.86s 1.95s
Bind Time 0.75s (± 1.26%) 0.67s (± 1.30%) -0.08s (-10.58%) 0.65s 0.69s
Check Time 5.41s (± 0.46%) 5.39s (± 0.61%) -0.02s (- 0.42%) 5.34s 5.47s
Emit Time 2.89s (± 1.99%) 2.70s (± 0.44%) -0.19s (- 6.44%) 2.68s 2.73s
Total Time 10.66s (± 0.51%) 10.65s (± 0.50%) -0.01s (- 0.13%) 10.55s 10.80s
TFS - node (v8.9.0, x86)
Memory used 181,023k (± 0.01%) 170,863k (± 0.03%) -10,161k (- 5.61%) 170,780k 170,969k
Parse Time 1.32s (± 1.00%) 1.58s (± 1.67%) +0.26s (+20.11%) 1.53s 1.65s
Bind Time 0.69s (± 0.72%) 0.60s (± 1.14%) -0.10s (-14.24%) 0.58s 0.61s
Check Time 4.49s (± 0.53%) 4.43s (± 0.49%) -0.06s (- 1.23%) 4.38s 4.47s
Emit Time 2.93s (± 0.77%) 2.81s (± 1.39%) -0.13s (- 4.36%) 2.71s 2.89s
Total Time 9.43s (± 0.38%) 9.42s (± 0.56%) -0.02s (- 0.16%) 9.24s 9.49s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory6 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
Benchmark Name Iterations
Current 35282 10
Baseline master 10

@ajafff
Copy link
Contributor

ajafff commented Dec 29, 2019

What's the benefit of having to use context.factory in transforms and how is it different from ts.factory?

@rbuckton
Copy link
Member Author

rbuckton commented May 8, 2020

What's the benefit of having to use context.factory in transforms and how is it different from ts.factory?

The current factory methods mark nodes as Synthesized and do some other work don't make sense for some situations. Since the new NodeFactory API allows for a number of additional hooks for when nodes are created and updated, it is better for a transformer to rely on the NodeFactory provided to it, as that will eventually allow us to be more flexible with transformations in the future.

For example, the parser now utilizes a custom NodeFactory that can explicitly set parent pointers as the AST is constructed:

const factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters, baseNodeFactory, {
onSetChild(parent, child) {
if (setParentNodes) {
setParent(child, parent);
}
},
onSetChildren(parent, children) {
if (setParentNodes) {
setEachParent(children, parent);
}
},
onFinishNode(node) {
if (setParentNodes) {
if (hasJSDocNodes(node)) {
setEachParent(node.jsDoc, node);
}
}
},
onCreateNode(_) {
nodeCount++;
}
});

The existing factory methods will still be available for some period of time with deprecations: https://github.com/microsoft/TypeScript/blob/086633f4db521efb6bc25aadaca68f457e56a95b/src/compat/deprecations.ts. This model allows us to introduce deprecations with different levels of aggressiveness:

  • Soft - Deprecations in documentation only.
  • Warn - Deprecations that attempt to warn you when used (usually via console.log if available).
  • Error - Deprecations that throw errors when used.
  • Removed - The deprecated API is completely removed from the package.

@rbuckton rbuckton marked this pull request as ready for review May 8, 2020 02:13
@rbuckton
Copy link
Member Author

rbuckton commented May 8, 2020

@typescript-bot perf test

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 8, 2020

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

# Conflicts:
#	src/compiler/factoryPublic.ts
#	src/services/codefixes/convertToAsyncFunction.ts
#	src/services/codefixes/helpers.ts
#	src/services/codefixes/inferFromUsage.ts
#	src/services/signatureHelp.ts
#	tests/baselines/reference/api/tsserverlibrary.d.ts
#	tests/baselines/reference/api/typescript.d.ts
# Conflicts:
#	src/compiler/binder.ts
#	src/compiler/checker.ts
#	src/compiler/factory.ts
#	src/compiler/transformers/declarations.ts
#	src/compiler/transformers/es2015.ts
#	src/compiler/transformers/module/module.ts
#	src/compiler/transformers/module/system.ts
#	src/compiler/transformers/taggedTemplate.ts
#	src/compiler/transformers/ts.ts
#	src/compiler/utilities.ts
#	src/compiler/visitor.ts
#	src/harness/vfsUtil.ts
#	src/services/codefixes/addMissingAsync.ts
#	src/services/codefixes/convertToMappedObjectType.ts
#	src/services/codefixes/helpers.ts
#	src/services/completions.ts
#	src/services/refactors/generateGetAccessorAndSetAccessor.ts
@rbuckton
Copy link
Member Author

I'm going to merge master into this one more time to make sure there aren't any new changes that need to be captured, then I can merge this to master.

@nonara
Copy link

nonara commented Jun 26, 2020

Nice work! Was a decision made on the renaming proposal?

@rbuckton
Copy link
Member Author

Yes, we merged #39058 which used the more consistent and clearer names for factory methods.

@72636c 72636c mentioned this pull request Aug 21, 2020
1 task
edsrzf added a commit to edsrzf/ts-migrate that referenced this pull request Oct 24, 2020
Most ts.create* and ts.update* functions are deprecated as of TypeScript 4.0. The
current plan is to emit noiser and noisier warnings with each version
until the deprecated functions are removed in 4.3.

See this pull request for more details:
microsoft/TypeScript#35282

Some method signatures and names have changed slightly.

The easy way to update is to use the global ts.factory object.
TypeScript transformations also have access to a NodeFactory in their
transformation contexts.

Note that we still use the deprecate getMutableClone function because
its replacement is not included in the TypeScript declarations. See
microsoft/TypeScript#40507
@orta orta mentioned this pull request Oct 30, 2020
5 tasks
@jakebailey jakebailey deleted the nodeFactory branch November 7, 2022 17:37
jasonreyes9 added a commit to jasonreyes9/ts-migrate that referenced this pull request Oct 31, 2023
Most ts.create* and ts.update* functions are deprecated as of TypeScript 4.0. The
current plan is to emit noiser and noisier warnings with each version
until the deprecated functions are removed in 4.3.

See this pull request for more details:
microsoft/TypeScript#35282

Some method signatures and names have changed slightly.

The easy way to update is to use the global ts.factory object.
TypeScript transformations also have access to a NodeFactory in their
transformation contexts.

Note that we still use the deprecate getMutableClone function because
its replacement is not included in the TypeScript declarations. See
microsoft/TypeScript#40507
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.

9 participants