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(v2): unblock metadata processing when possible #2054

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

endiliey
Copy link
Contributor

@endiliey endiliey commented Nov 25, 2019

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

image

Old approach is something like

async function oldApproach(source) {
  const {id, title} = await fakeReadFile(source);
  const version = getVersion(source);

  // do something else
  
  return {
    id,
    title,
    version,
  }
}

Now it's like

async function newApproach(source) {
  const frontMatterPromise = fakeReadFile(source);
  const version = getVersion(source);

  // do something else
  
  const {id, title} = await frontMatterPromise;
  
  return {
    id,
    title,
    version,
  }
}

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
passing test

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 25, 2019
@endiliey endiliey added the pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. label Nov 25, 2019
@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 1a8a5e6

https://deploy-preview-2054--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-preview ready!

Built with commit 1a8a5e6

https://deploy-preview-2054--docusaurus-preview.netlify.com

@yangshun yangshun merged commit be39616 into master Nov 25, 2019
@endiliey endiliey deleted the endi/metadataunblock branch November 26, 2019 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants