Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Before this, we can parse 1333 nested if-statements. Afterwards, we get up to 1443. This is a simple increase of >8%.

We do this by breaking out block-parsing into two separate helpers. One used for method/accessor blocks and one for normal statement-blocks.

This allows us to keep all specialized parsing/stack-space for the method case, while keeping the statement-version extremely simple and lightweight.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner February 13, 2020 01:13
@CyrusNajmabadi
Copy link
Member Author

Tagging @RikkiGibson @jcouv .

WIth this change (and my other PRs) we no longer have any regression in nested-statement-parsing (even when supporting attributes on all statements).

Copy link
Member Author

Choose a reason for hiding this comment

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

unused. deleted.

@CyrusNajmabadi
Copy link
Member Author

Ping jcouv on this one as well.


// There's a special error code for a missing token after an accessor keyword
var openBrace = isAccessorBody && this.CurrentToken.Kind != SyntaxKind.OpenBraceToken
CSharpSyntaxNode openBrace = isAccessorBody && this.CurrentToken.Kind != SyntaxKind.OpenBraceToken
Copy link
Member

@RikkiGibson RikkiGibson Feb 13, 2020

Choose a reason for hiding this comment

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

is an explicit variable type required here?

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 makes things cleaner. we later on call a method that takes a ref CSharpSyntaxNode. so this avoids having to copy this SyntaxToken into a CSharpSyntaxNode and back again.

{
_pool.Free(statements);
}
_pool.Free(statements);
Copy link
Member

Choose a reason for hiding this comment

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

good call on removing the try/finally, that by itself can increase stack frame size and prevent inlining.

I am assuming that when we're in a situation that we throw an exception while parsing the block, that presents as a non-recoverable error in the IDE? So we don't have to worry about carrying on while leaking memory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.

Note: we dont' actually 'leak' in that case. We merely don't get as much pooled reuse of these data structures as we woudl otherwise. However, that's really not important enough to impact a more relevant scenario like "how much can we parse".

The major downside here is that you have to be more careful to not 'early return'. So i only do this sort of thing when the code is simple enough that it's easy to visually validate that the pooled resources are returned.


var block = _syntaxFactory.Block(
(SyntaxToken)openBrace,
statements,
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 so confusing. it makes it look like you're creating the block, then freeing something used to create it, then returning the block. i.e. a bad bug. I would really like to see this conversion removed (SyntaxListBuilder->SyntaxList)

Copy link
Member Author

Choose a reason for hiding this comment

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

happy to do that in a future PR. i also do not like the implicit conversion from builder to list.

@RikkiGibson RikkiGibson requested a review from a team February 13, 2020 18:04
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Auto-approval

@RikkiGibson RikkiGibson added this to the 16.6 milestone Feb 13, 2020
@RikkiGibson RikkiGibson added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Feb 13, 2020
@ghost ghost merged commit 76bdeb8 into dotnet:master Feb 13, 2020
@CyrusNajmabadi
Copy link
Member Author

Thanks!

@CyrusNajmabadi CyrusNajmabadi deleted the blockStackFrames branch February 13, 2020 20:21
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers auto-merge Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants