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 markdown processing performance #75

Merged
merged 1 commit into from
May 20, 2022

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented May 20, 2022

Fixes #40

I found that the cause of poor performance and high resource usage was the use of a lookbehind in the regex expression used to locate <img> elements in markdown.

This PR removes the lookahead and lookbehind, and instead extracts out the $$render portion first, then looks through it, instead of the entire code string. This is much more performant. In my own project, which only has one markdown page with images in it, the overall build time went from

[build] 21 page(s) built in 61.67s

to

[build] 21 page(s) built in 19.37s

@vercel
Copy link

vercel bot commented May 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Updated
astro-imagetools-demo ⬜️ Ignored (Inspect) May 20, 2022 at 3:37PM (UTC)
astro-imagetools-docs ⬜️ Ignored (Inspect) May 20, 2022 at 3:37PM (UTC)

@RafidMuhymin
Copy link
Owner

@IanVS are you sure that this change will fix #41 too. The example provided by OP doesn't have any images inside the markdown files.

@IanVS
Copy link
Contributor Author

IanVS commented May 20, 2022

Good call, something else seems to be going on there. Looking into it now, and I've updated the description.

@RafidMuhymin
Copy link
Owner

Thank you for this important fix @IanVS ! 🥇

@RafidMuhymin RafidMuhymin merged commit 29cc7f5 into RafidMuhymin:main May 20, 2022
@IanVS IanVS deleted the markdown-perf branch May 20, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Astro builds timing out then getting killed
2 participants