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

dev: set some next settings to improve build times #998

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

tefkah
Copy link
Member

@tefkah tefkah commented Feb 26, 2025

Issue(s) Resolved

Next builds are long.

High-level Explanation of PR

TLDR: total CI time decrease for building core is 1m30s!! very nice

Enables experimental.parallelServerBulldTraces in next.config.mjs. This makes the tracing of server routes take place in a separate worker, which slightly decreases build times (ideally).

As you can see below, this results in ~50s or roughly 19% faster next builds! Seems great for doing literally nothing.

Additionally, I disable webpack caching in line with this next recommendation. Currently serializing and writing the webpack cache takes a long time, we even get this warning often

<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (243kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)

Disabling this cache writing results in an additional 40s saved.

In total, this results in a 33% decrease in next build times!!

This is imo still crazy slow, but at least it's slightly less so.

Note

The webpack cache is very useful, in theory. If we could effectively cache it, subsequent builds would be substantially faster.
I've not been able to figure out how to do this in docker yet though (caching docker layers is prohibitively slow, we should not do it).
We could only disable the webpack cache on CI, but i'm personally very rarely doing repeated builds myself without doing a next dev in between, so i'd rather have a faster initial build locally than faster rebuilds.

In CI

Time is last step of #24 the step Build, Tag, and Push to ECR

Main

https://github.com/pubpub/platform/actions/runs/13527437906/job/37801720865

#24 DONE 275.4s

https://github.com/pubpub/platform/actions/runs/13541214032/job/37842525354?pr=998
+ webpackBuildWorker + parallelServerBuildTraces

#24 DONE 223.2s

https://github.com/pubpub/platform/actions/runs/13542305151/job/37845940104?pr=998

+ webpackBuildWorker + parallelServerBuildTraces + cache freeze

#24 DONE 183.5s

Improvement of 50ish seconds, not bad!

On my machine

result of running

rm -rf .next && time pnpm --filter core build

Main

      127.14 real       210.20 user        32.80 sys       

+ webpackBuildWorker

      102.50 real       183.38 user        31.65 sys

+ webpackBuildWorker + parallelServerBuildTraces

      93.87 real       157.80 user        28.09 sys

So a 30ish to 60ish second decrease, pretty nice!

+ webpackBuildWorker + parallelServerBuildTraces + cache freeze

       75.88 real       107.77 user        16.19 sys

An additional 50sec decrease! very nice

Test Plan

Run build locally, hopefully do not get OOM errors.

Check that Sentry sourcemaps are still being uploaded correctly (should not be influenced i think)

Screenshots (if applicable)

Notes

@tefkah tefkah changed the title dev: enable experimental parallel traces to improve build times somewhat dev: enable experimental parallel traces to improve build times Feb 26, 2025
@@ -52,6 +52,8 @@ const nextConfig = {
],
experimental: {
optimizePackageImports: ["@icons-pack/react-simple-icons", "lucide-react"],
webpackBuildWorker: true,
Copy link
Member Author

@tefkah tefkah Feb 26, 2025

Choose a reason for hiding this comment

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

this needs to be specifically enabled for parallelServerBuildTraces to work

@tefkah tefkah changed the title dev: enable experimental parallel traces to improve build times dev: set some next settings to improve build times Feb 26, 2025
Comment on lines +61 to +65
if (config.cache && !dev) {
config.cache = Object.freeze({
type: "memory",
});
}
Copy link
Member Author

Choose a reason for hiding this comment

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

as mentioned in the pr, we could theoretically add && env.CI here to only have this happen on CI, but i prefer shorter initial build times locally as well

@3mcd
Copy link
Member

3mcd commented Feb 26, 2025

Wow, just tested locally. Prior to your changes:

pnpm --filter=core build  133.87s user 20.98s system 215% cpu 1:11.99 total

After your changes:

pnpm --filter=core build  81.73s user 11.75s system 190% cpu 49.179 total

So yeah, about a 50 second improvement. Super nice!

@3mcd 3mcd merged commit 626e97e into main Feb 26, 2025
6 checks passed
@3mcd 3mcd deleted the tfk/parallel-trace-builds branch February 26, 2025 19:01
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.

2 participants