Skip to content

Use NodeFlags to detect nodes in ambient contexts instead of climbing ancestors #17831

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
7 commits merged into from
Nov 3, 2017

Conversation

ghost
Copy link

@ghost ghost commented Aug 16, 2017

This is basically the same as #17721.
Previously when checking for an ambient context, we would climb ancestors looking for something with an ambient modifier -- but usually there would be none and we would climb all the way to the root.
Now we just check against a flag that is set in the parser.
This seems to improve bind time by an average of 5% and check time by an average of 3%, with average total improvement of 1%.

Monaco - node (v8.2.1, x64)

Project Baseline Current Delta Best Worst
Memory used 357,006k (± 0.00%) 356,995k (± 0.01%) -11k (- 0.00%) 356,949k 357,143k
Parse Time 2.10s (± 1.10%) 2.08s (± 0.36%) -0.02s (- 0.86%) 2.06s 2.09s
Bind Time 0.81s (± 1.15%) 0.77s (± 0.39%) -0.04s (- 4.95%) 0.76s 0.77s
Check Time 4.19s (± 0.60%) 4.14s (± 0.40%) -0.05s (- 1.24%) 4.10s 4.17s
Emit Time 2.77s (± 0.73%) 2.78s (± 0.50%) +0.01s (+ 0.22%) 2.75s 2.81s
Total Time 9.87s (± 0.45%) 9.76s (± 0.25%) -0.11s (- 1.11%) 9.70s 9.82s

Monaco - tsc (x86)

Project Baseline Current Delta Best Worst
Parse Time 1.51s (± 3.64%) 1.49s (± 0.95%) -0.02s (- 1.19%) 1.46s 1.53s
Bind Time 0.58s (± 1.82%) 0.52s (± 2.20%) -0.06s (- 10.45%) 0.51s 0.56s
Check Time 3.98s (± 0.98%) 3.80s (± 1.40%) -0.18s (- 4.45%) 3.69s 3.91s
Emit Time 7.54s (± 6.52%) 7.46s (± 1.39%) -0.09s (- 1.14%) 7.34s 7.84s
Total Time 13.61s (± 3.93%) 13.27s (± 1.15%) -0.34s (- 2.48%) 13.02s 13.71s

TFS - node (v8.2.1, x64)

Project Baseline Current Delta Best Worst
Memory used 309,696k (± 0.01%) 309,664k (± 0.01%) -32k (- 0.01%) 309,620k 309,693k
Parse Time 1.53s (± 1.92%) 1.54s (± 0.26%) +0.01s (+ 0.65%) 1.53s 1.55s
Bind Time 0.68s (± 4.95%) 0.65s (± 0.92%) -0.04s (- 5.69%) 0.64s 0.66s
Check Time 3.60s (± 0.51%) 3.53s (± 0.52%) -0.06s (- 1.78%) 3.49s 3.57s
Emit Time 2.45s (± 0.33%) 2.45s (± 0.60%) -0.00s (- 0.08%) 2.41s 2.48s
Total Time 8.26s (± 0.33%) 8.17s (± 0.36%) -0.09s (- 1.14%) 8.10s 8.22s

TFS - tsc (x86)

Project Baseline Current Delta Best Worst
Parse Time 1.09s (± 5.00%) 1.08s (± 1.75%) -0.01s (- 0.83%) 1.05s 1.13s
Bind Time 0.58s (± 5.24%) 0.54s (± 2.78%) -0.04s (- 6.56%) 0.51s 0.58s
Check Time 3.26s (± 1.15%) 3.10s (± 1.86%) -0.15s (- 4.64%) 3.01s 3.24s
Emit Time 4.44s (± 1.49%) 4.51s (± 1.27%) +0.06s (+ 1.46%) 4.43s 4.72s
Total Time 9.37s (± 1.10%) 9.23s (± 1.22%) -0.14s (- 1.45%) 9.01s 9.60s

@ghost
Copy link
Author

ghost commented Aug 29, 2017

@rbuckton Any comments?

@@ -613,19 +613,21 @@ namespace ts {
let parseErrorBeforeNextFinishedNode = false;

export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile {
const isDeclarationFile = isDeclarationFileName(fileName);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to thread this through? Can we not just set the context flag in createSourceFile?

@@ -31,7 +31,8 @@ namespace ts.BreakpointResolver {
}

// Cannot set breakpoint in ambient declarations
if (isInAmbientContext(tokenAtLocation)) {
// (Tokens do not have flags set, but their parents do.)
Copy link
Member

Choose a reason for hiding this comment

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

This is surprising, wouldn't this result in breaks in the incremental parser?

Copy link
Member

Choose a reason for hiding this comment

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

We call parseTokenNode for tokens. parseTokenNode in turn calls finishNode, which should set these flags. If a token doesn't have the correct context then we should investigate why.

@ghost
Copy link
Author

ghost commented Sep 22, 2017

@rbuckton good to go?

@ghost
Copy link
Author

ghost commented Oct 22, 2017

@rbuckton Bump

@ghost
Copy link
Author

ghost commented Oct 30, 2017

@rbuckton

Copy link
Member

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

A few more minor comments.

@@ -5089,6 +5104,18 @@ namespace ts {
const fullStart = getNodePos();
const decorators = parseDecorators();
const modifiers = parseModifiers();
if (modifiers && modifiers.some(m => m.kind === SyntaxKind.DeclareKeyword)) {
Copy link
Member

Choose a reason for hiding this comment

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

Could just do if (some(modifiers, m => m.kind === SyntaxKind.DeclareKeyword)) as this does the existential check for you.

@@ -17081,7 +17081,7 @@ namespace ts {
if (targetDeclarationKind !== SyntaxKind.Unknown) {
const decl = getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
// function/variable declaration should be ambient
return isInAmbientContext(decl);
return decl.flags & NodeFlags.Ambient;
Copy link
Member

Choose a reason for hiding this comment

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

!!(decl.flags & NodeFlags.Ambient), otherwise the return type becomes number | boolean.

@@ -22740,7 +22740,7 @@ namespace ts {
}
}
else {
if (modulekind >= ModuleKind.ES2015 && !isInAmbientContext(node)) {
if (modulekind >= ModuleKind.ES2015 && !((node as ImportEqualsDeclaration).flags & NodeFlags.Ambient)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is the cast necessary?

@rbuckton
Copy link
Member

The build is failing due to a public API change. Can you verify whether the baseline changes are acceptable?

@rbuckton
Copy link
Member

Approved, once the build passes.

@ghost ghost merged commit cc2a2a7 into master Nov 3, 2017
@ghost ghost deleted the ambient branch November 3, 2017 15:08
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants