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

Improve build perf #2697

Merged
merged 2 commits into from
Mar 2, 2022
Merged

Improve build perf #2697

merged 2 commits into from
Mar 2, 2022

Conversation

FredKSchott
Copy link
Member

@FredKSchott FredKSchott commented Mar 1, 2022

Changes

While working on the docs repo, I chased down two performance issues related to docs build:

  1. ssrPreload appears to be mostly serial work, so 142+ pages of of docs inside a Promise.all() all blocked each other from completing. This hung the build entirely when I switched the docs parser over to Shiki (see next).
  2. Our Shiki markdown plugin and Code component are both unoptimized. After digging into why the build failed once moving over to Shiki, i tracked down the fact that getHighlighter is the most expensive part of shiki, and we were calling it once per page. Caching this for later returned improvement to previous Prism-levels.

@sarah11918 FYI both of these together were causing the failing builds you were seeing when we enabled that config change.

Testing

  • Covered by existing tests, all changes were perf based

Docs

  • N/A

@changeset-bot
Copy link

changeset-bot bot commented Mar 1, 2022

🦋 Changeset detected

Latest commit: 85140d7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@astrojs/markdown-remark Patch
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) feat: markdown Related to Markdown (scope) labels Mar 1, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

LGTM! Nice improvements. 👍🏻

Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

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

lgtm! I'd be curious to see if there's any gains by parallelizing in chunks or with a worker pool, but I'm totally on-board with simplifying this now and looking into optimizations down the road 👍

@matthewp
Copy link
Contributor

matthewp commented Mar 2, 2022

lgtm, we can also potentially remove preload entirely if we were to make it a rule that the <Component> name matches the import import Component from './whatever'; That would mean you couldn't do:

---
import Namespace from 'namespace';
const Div = Namespace.Div;
---

<Div />

But we could support this instead:

---
import Namespace from 'namespace';
---

<Namespace.Div />

Seems like an ok restriction to me.


edit: this restriction really only needs to apply to client: components. Server-only ones does not matter. We would need it for client: so that the compiler statically would know which files to bundle.

@matthewp
Copy link
Contributor

matthewp commented Mar 2, 2022

Note that there are a couple of (code) changes that would be needed to get rid of the preload step, but that's the only one that would be a breaking change (I think).

@matthewp
Copy link
Contributor

matthewp commented Mar 2, 2022

Thinking more about it, using runtime variables as component names for client component is already not going to work, so this restriction already kind of exists just not officially.

@natemoo-re natemoo-re merged commit 91765d7 into main Mar 2, 2022
@natemoo-re natemoo-re deleted the speed-up-shiki-md branch March 2, 2022 22:09
@github-actions github-actions bot mentioned this pull request Mar 2, 2022
@FredKSchott
Copy link
Member Author

lgtm, we can also potentially remove preload entirely if we were to make it a rule that the <Component> name matches the import import Component from './whatever'; That would mean you couldn't do:

---
import Namespace from 'namespace';
const Div = Namespace.Div;
---

<Div />

But we could support this instead:

---
import Namespace from 'namespace';
---

<Namespace.Div />

Seems like an ok restriction to me.

edit: this restriction really only needs to apply to client: components. Server-only ones does not matter. We would need it for client: so that the compiler statically would know which files to bundle.

I would be okay with this if there's a really clear error or warning when you break the rule.

SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* improve md perf

* chore: add changesets

Co-authored-by: Nate Moore <nate@skypack.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants