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

Fix shiki perf issue pt. 2 #2870

Merged
merged 1 commit into from
Mar 24, 2022
Merged

Fix shiki perf issue pt. 2 #2870

merged 1 commit into from
Mar 24, 2022

Conversation

FredKSchott
Copy link
Member

Changes

Testing

  • Tested on ddt

Docs

  • N/A

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2022

🦋 Changeset detected

Latest commit: 7421609

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

This PR includes changesets to release 1 package
Name Type
@astrojs/markdown-remark 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 the feat: markdown Related to Markdown (scope) label Mar 24, 2022
@FredKSchott FredKSchott force-pushed the fix-shiki-perf branch 2 times, most recently from 8bf3543 to e89448f Compare March 24, 2022 00:07
*/
const highlighterCache = new Map<string, shiki.Highlighter>();
const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
Copy link
Member

Choose a reason for hiding this comment

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

Always makes me nervous to cache promises, but this makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, see note below about wanting to refactor this post v1.0 beta (for perf but also to get rid of some edge case bugs related to this)

Comment on lines +49 to +50
// NOTE: There may be a performance issue here for large sites that use `lang`.
// Since this will be called on every page load. Unclear how to fix this.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... Happy to push this off for later. Thanks for adding a note!

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually lost a ton of time trying to refactor this yesterday to run once and reuse the created plugin across all parsers, but it turns out (as far as I could tell) you need a fresh parser & fresh plugins created for every file. The fact that we're doing so much async work in a plugin instantiation is a bit of an anti-pattern for unified, I think, but more than I could bite off here.

So there's probably some low-hanging perf wins to unlock in how our markdown parser works, but it was more than I could bite off in this PR.

@FredKSchott FredKSchott merged commit d763ec1 into main Mar 24, 2022
@FredKSchott FredKSchott deleted the fix-shiki-perf branch March 24, 2022 16:49
This was referenced Mar 24, 2022
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants