Skip to content

perf: made ogimage generation concurrent#2181

Open
tomoyanonymous wants to merge 4 commits intojackyzha0:v4from
tomoyanonymous:perf/ogimage-concurrent
Open

perf: made ogimage generation concurrent#2181
tomoyanonymous wants to merge 4 commits intojackyzha0:v4from
tomoyanonymous:perf/ogimage-concurrent

Conversation

@tomoyanonymous
Copy link
Contributor

This PR changes the for loop+yield used in the custom og image generation into just Promise.all+map.

In my website, the change turned the build speed from 10 minutes to 6 minutes in CI.

@github-actions
Copy link

github-actions bot commented Oct 30, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
quartz ✅ Ready (View Log) Visit Preview 59b836b

Comment on lines 117 to 123
Promise.all(
content.map(([_tree, vfile]) => {
if (vfile.data.frontmatter?.socialImage !== undefined) {
processOgImage(ctx, vfile.data, fonts, fullOptions)
}
}),
)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
Promise.all(
content.map(([_tree, vfile]) => {
if (vfile.data.frontmatter?.socialImage !== undefined) {
processOgImage(ctx, vfile.data, fonts, fullOptions)
}
}),
)
await Promise.all(
content.map(([_tree, vfile]) => {
if (vfile.data.frontmatter?.socialImage !== undefined) {
yield processOgImage(ctx, vfile.data, fonts, fullOptions)
}
}),
)

we still need to wait for the all the promises to finish before returning, also make sure to yield to the generator to report the file as emitted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't yield at there because it's inside map function and it is not a generator. I made change to entire emit function, not to be async generator but a normal async function which returns promise of array. Does it work? It seems working on my environment.

return []
},
async *emit(ctx, content, _resources) {
async emit(ctx, content, _resources): Promise<FilePath[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will be blocking. see quartz/build.ts.

I think this doesn't make that much of a different? at least when I tested with my vaults (around 2k notes, nested), it doesn't seem to have that much of a difference.

though, currently full build for my vault with main implementation takes around 3m, which i'm ok with (I'm building with m1 max chip, 32GB)

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.

3 participants