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

perf: improve ruleset loading #1188

Merged
merged 2 commits into from
May 29, 2020
Merged

perf: improve ruleset loading #1188

merged 2 commits into from
May 29, 2020

Conversation

P0lip
Copy link
Contributor

@P0lip P0lip commented May 29, 2020

copyRule unnecessarily performs a deep clone that is expensive at times due to the presence of oas2 & oas3 JSON Schema that need to be copied over.
We can perform a shallow copy here, as we do not alter the value of functionOptions while merging rules.
then is mutated however here, so we need to account for this.

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

Screenshots
Before:
image

After:
image
zoomed in :P
image

If applicable, add screenshots or gifs to help demonstrate the changes. If not applicable, remove this screenshots section before creating the PR.

Additional context

Not a big deal in case of CLI users, but fairly important for Studio users, as the Spectral activation is slower than it has to be.
Bonus change - we prefer JSON.parse when the filepath has .json extension or the url's pathname ends with .json.

Last but not least - a couple of ESLint warnings addressed.

@P0lip P0lip added the chore label May 29, 2020
@P0lip P0lip requested a review from nulltoken May 29, 2020 00:38
@P0lip P0lip self-assigned this May 29, 2020
@P0lip P0lip force-pushed the perf/ruleset-validation branch from 4c38133 to f7b0331 Compare May 29, 2020 00:38
@@ -15,6 +15,14 @@ export interface IRulesetReadOptions {
timeout?: number;
}

function parseContent(content: string, source: string): unknown {
if (extname(source) === '.json') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stoplight/path#extname handles URLs.
image

Copy link
Contributor

@nulltoken nulltoken left a comment

Choose a reason for hiding this comment

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

👍

@P0lip P0lip merged commit 1cef63f into develop May 29, 2020
@P0lip P0lip deleted the perf/ruleset-validation branch May 29, 2020 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants