rokucommunity / bslint

A linter for BrightScript and BrighterScript.
MIT License
27 stars 14 forks source link

Performance boost by lifting some global lookups #92

Closed TwitchBronBron closed 1 year ago

TwitchBronBron commented 1 year ago

Fixes a bug in the varTracking logic that was re-calculating the globals too frequently (for each file for each scope). Since the globals are shared across every file in that scope, we can lift that calculation.

Here's some pseudocode of what changed. Before:

for (const scope of scopes) {
    for (const file of scope.files) {
        const globals = getAllGlobalNamesInScope(scope);
        validateFile(scope, file, globals);
    }
}

After:

for (const scope of scopes) {
    const globals = getAllGlobalNamesInScope(scope);
    for (const file of scope.files) {
        validateFile(scope, file, globals);
    }
}

This shaved off 1,300ms from the validation cycle of a large internal project

Before:

Validating project finished. (6s531.186ms)

After:

Validating project finished. (5s224.474ms)