Skip to content

Memoize the processor in MarkdownHooks #909

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

Merged
merged 2 commits into from
Apr 21, 2025
Merged

Memoize the processor in MarkdownHooks #909

merged 2 commits into from
Apr 21, 2025

Conversation

remcohaszing
Copy link
Member

@remcohaszing remcohaszing commented Apr 18, 2025

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

Some plugins may perform heavy work in preparation to make the transformer light-weight. A good example of this is rehype-starry-night.

Without this change, an interactive markdown editor which includes rehype-starry-night is very sluggish. With this change, performance is as good as if rehype-starry-night isn’t even used.

Fix https://github.com/orgs/rehypejs/discussions/194

Some plugins may perform heavy work in preparation to make the
transformer light-weight. A good example of this is
`rehype-starry-night`.

Without this change, an interactive markdown editor which includes
`rehype-starry-night` is very sluggish. With this change, performance is
as good as if `rehype-starry-night` isn’t even used.
@remcohaszing remcohaszing added 🏁 area/perf This affects performance 👶 semver/patch This is a backwards-compatible fix 🦋 type/enhancement This is great to have 🌐 platform/browser This affects browsers 🤞 phase/open Post is being triaged manually labels Apr 18, 2025
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2245c64) to head (087408f).
Report is 48 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #909    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            3         3            
  Lines         1354      1743   +389     
  Branches       113       123    +10     
==========================================
+ Hits          1354      1743   +389     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@JounQin JounQin left a comment

Choose a reason for hiding this comment

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

LGTM

lib/index.js Outdated
@@ -212,7 +212,10 @@ export async function MarkdownAsync(options) {
* React node.
*/
export function MarkdownHooks(options) {
const processor = createProcessor(options)
const processor = useMemo(
() => createProcessor(options),
Copy link
Member

Choose a reason for hiding this comment

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

please use a regular function, thanks

@wooorm wooorm merged commit fda7fa5 into main Apr 21, 2025
6 checks passed
@wooorm wooorm deleted the memoize-processor branch April 21, 2025 10:10

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Apr 21, 2025
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Apr 21, 2025
@wooorm
Copy link
Member

wooorm commented Apr 21, 2025

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏁 area/perf This affects performance 💪 phase/solved Post is done 🌐 platform/browser This affects browsers 👶 semver/patch This is a backwards-compatible fix 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

3 participants