-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: reuse Shiki highlighters per theme/lang #3130
Conversation
🦋 Changeset detectedLatest commit: 0f023d0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
// Highlighter has already been requested, reuse the same instance | ||
if (_resolvedHighlighters.has(key)) { return _resolvedHighlighters.get(key) } | ||
|
||
// Start the async getHighlighter call and cache the Promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a bit more poking around and confirmed that this looks like the memory issue was just due to pages being built in parallel. Each page initialized a highlighter and Node couldn't garbage collect them in between page builds
Caching the promise here makes sure that each page gets an immediate response and they can all share the same highlighter instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah nice, we had to do this in the remark plugin also, wish we could reuse more logic between teh two!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* reuse Shiki highlighters per theme/lang * chore: adding changeset
Changes
Fixes #3110
This updates the built-in
<Code>
component to reuse Shiki highlighters based on thetheme
andlang
propertiesTesting
Tested locally against the astro-imagetools docs site
Before
Error: fail to memory allocation
After
Docs
N/A