perf: made ogimage generation concurrent#2181
perf: made ogimage generation concurrent#2181tomoyanonymous wants to merge 4 commits intojackyzha0:v4from
Conversation
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
quartz/plugins/emitters/ogImage.tsx
Outdated
| Promise.all( | ||
| content.map(([_tree, vfile]) => { | ||
| if (vfile.data.frontmatter?.socialImage !== undefined) { | ||
| processOgImage(ctx, vfile.data, fonts, fullOptions) | ||
| } | ||
| }), | ||
| ) |
There was a problem hiding this comment.
| 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
There was a problem hiding this comment.
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[]> { |
There was a problem hiding this comment.
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)
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.