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

Scope validation performance boost #656

Merged
merged 17 commits into from
Sep 20, 2022
Merged

Conversation

TwitchBronBron
Copy link
Member

@TwitchBronBron TwitchBronBron commented Aug 2, 2022

Several fixes:

While this hasn't restored the original performance lost in 0.53.0, it's a step in the right direction.
image

Breaking changes:

  • removed NamespaceStatement.symbolTable in favor of NamespaceStatement.getSymbolTable() because the symbol table for namespaces actually reside within the NamespaceStatement.body property. Since the symbolTable logic was only recently added, it's unlikely that many projects are referencing it.

  • removed the namespaceName from several AstNodes, in favor of external consumers needing to call .findAncestor(isNamespaceStatement) instead. Note, this relies heavily on the AstNode.parent property which is set at the start of onFileValidate for each file. This is breaking because previously, the .namespaceName property was available immediately in afterFileParse. However, that logic was unsustainable for plugins that manipulate AST, and it's unlikely that many plugins are leveraging that property, so it is worth the breaking change.

    Here are the nodes with the removed property:

    • VariableExpression
    • DottedGetExpression
    • CallExpression
    • FunctionStatement

@TwitchBronBron TwitchBronBron changed the title Validation perf boost Scope validation performance boost Aug 2, 2022
@TwitchBronBron TwitchBronBron self-assigned this Sep 1, 2022
@TwitchBronBron
Copy link
Member Author

Some of the fixes have further improved performance. Still not as good as 0.52.3, but better than when this PR was originally submitted.
image


//do some file-based validations
if (isEnumStatement(node)) {
this.validateEnumDeclaration(node);
Copy link
Member Author

Choose a reason for hiding this comment

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

This was moved into the EnumStatement callback above.


public processEvent(event: OnScopeValidateEvent) {
this.events.push(event);
event.scope.linkSymbolTable();
Copy link
Member Author

Choose a reason for hiding this comment

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

Symbol table linking/unlinking happens at the program event level, we don't need to do it here anymore.

private iterateFileExpressions(file: BrsFile) {
const { scope } = this.event;
//build an expression collection ONCE per file
const expressionInfos = this.expressionsByFile.getOrAdd(file, () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the core of the performance improvement. The expression info is computed once for each file (previously this would happen once per scope per file).

@TwitchBronBron TwitchBronBron merged commit 4ce448f into master Sep 20, 2022
@TwitchBronBron TwitchBronBron deleted the validation-perf-boost branch September 20, 2022 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant