-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Render templates in parallel. #3277
base: main
Are you sure you want to change the base?
Conversation
This would be extremely helpful! |
Hmm. I’m not opposed to this one! I do think the new https://www.11ty.dev/docs/plugins/image/#optimize-images-on-request Anecdotally, I didn’t see any build performance benefits to this approach in 11ty.dev or zachleat.com. And https://github.com/11ty/eleventy-benchmark seems about 4% slower in one small test:
Can anyone else test this one? |
Nice! But if I understand correctly this would only help for the local development server. I was also interested in improving performance when deploying on github pages. eleventy-img is an obvious use case for building in parallel because I assume it's used on many eleventy website. The other (maybe more interesting?) use case I have in mind is to allow web site authors to use workers in shortcodes. My website generates svg charts based on reading data files, and it would be nice to be able to move the computation of the charts to other threads.
I'm not completely sure how I should run the benchmark to reproduce. I've tried doing this:
And then the result I see is:
I'm not sure I'm doing this right. |
Running the benchmark a second time gives me:
which makes me wonder if the difference is within the noise level. As an aside, The change I made to
|
Happy to merge improvements to the script! For the benchmark, I modify this https://github.com/11ty/eleventy-benchmark/blob/08d5a4942e6b65f145e374ec72f991d0eec3a231/bench.sh#L9 and If |
I guess if I wanted to make improvements, I would make the script output profiles using https://www.npmjs.com/package/11ty-fx-profiler to make it possible to visualize what took more or less time between different runs.
Seems similar to what I've done. ../eleventy was my local fork with this PR applied. |
For Eleventy sites with templates using shortcodes that do a lot of computation, rendering the template is the part of the build that takes the longest. This part is done sequentially.
This PR makes it happen in parallel, limiting the concurrency to the core count.
Example profiles, using the 11ty-website site as an example for benchmarking:
I zoomed all profiles to the time range when templates are rendered.
The saving is larger for my own website, going from 10s to 3.4s to render my templates.
Rendering in parallel helps mostly for cases where the templates trigger async code that can perform some of its work off main thread. This is the case for resizing images with eleventy-img. This would also enable using workers to move heavy JS computations of shortcodes off of the main thread (without this PR, moving work to a worker is pointless as the main thread is blocked waiting for the result).