perf(v2): unblock metadata processing when possible #2054
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Await pauses the execution of current async function and waits for the passed Promise's resolution, and then resumes the async function's execution
In
metadata.ts
, we can actually increase the performance a little bit by making the readFile as promise, then continue resuming the function execution, only when we then really need the data. we await the promise.I created a simple benchmark to sort of describe the situation
https://runkit.com/endiliey/await-readfile-vs-readfile-as-promise/1.0.0
Old approach is something like
Now it's like
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
Docs plugin is covered by tests, so since it passes, regression is less likely