-
Notifications
You must be signed in to change notification settings - Fork 101
[DRAFT] feat! replace webpack by rsbuild for faster build #252
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
base: release
Are you sure you want to change the base?
Conversation
Is there anything you found that doesn't work / isn't supported by rsbuild? If not, we should just replace it everywhere and not just for tutor-mfe. |
No, I haven't. That's because there's nothing magical with our MFEs: they are just frontend code, bundled as regular js/html/css/images etc. That being said, I haven't extensively tested the 10 officially maintained MFEs, so it's quite possible I missed some issues.
I'm not sure anymore about that. While I worked on this project, I discovered some places where the webpack abstraction leaked into the MFE codebase, and that really feels like an anti-pattern. Instead, I now think that we should remove all of the build code from all MFE. There shouldn't be any MFE-specific build step. There should be a simple, documented standard to build any MFE. And we should be able to run something like |
Note that the locked cache in `rsbuild build` prevents concurrent builds. This means that we no longer have to limit the parallelism of the Docker builder, as we used to: https://docs.tutor.edly.io/troubleshooting.html#high-resource-consumption-by-docker-on-tutor-images-build
This makes sense to me, and I think it may even have been the original idea behind |
I tested this out on an Arm64 machine (M1 Macbook) and it seems that the rsbuild step breaks on arm64 native images. Here's the traceback:
I then tried it out by building it using the amd64 platform using the command: The results were impressive nonetheless even with amd64 emulation with the build layers taking 2-3x less time than when we were using webpack. |
Thanks for testing @Danyal-Faheem! Would you mind trying out debugging with |
@regisb, Running with both
|
I tested this branch on Macbook M2 and got the same error as Danyal mentioned above #252 (comment). However, even when I specified the platform (amd/64) in build argument, the build process did not complete and gave the same error. npm connection errors were happening as well, which has been more prominent than other build issues for me (even though I am using max2cpu config). I am adding some stats below:
|
I was able to reproduce the issue by building on a remote arm64 server:
The issue disappears when I disable the cache, which is tagged as "experimental". So what I did was to disable caching on arm64. I also filed the following upstream issue: web-infra-dev/rspack#10118 Thus, Apple users should now be able to test this PR again. 👀 @Danyal-Faheem @DawoudSheraz |
Caching should be disabled on this platform until the following issue is resolved: web-infra-dev/rspack#10118
@regisb I tested it with the updated commits and It's building on arm64 natively now! The results are also impressive: Running with a max-parallelism of 2 (I had to do this otherwise the Some stats: Build Time Comparison
I think this is really impressive but we will have to make changes to the |
This is the result of a long investigation to accelerate the building of MFE apps in Open edX. Many of the intermediate results can be found in this issue: openedx/wg-frontend#184
The tl;dr is that building MFEs takes a very long time, and that's because of Webpack. In this PR, we replace Webpack by rsbuild, resulting in a considerable performance improvement.
This PR is dependent on the following upstream PRs:
Open questions
TODO
Things we need to address before (if?) we merge:
Benchmarks
Configuration
These benchmarks are performed on my personal computer: a Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz with 4 processors and 20 GB RAM. My custom Docker builder runs with
max-parallelism = 4
, as per these instructions:All plugins are disabled, except for "mfe" and "forum", and there is no bind-mount:
The "mfe" image is built from scratch on the "main" branch; then, we re-build the image by clearing the cache for the "*-prod" build steps, which are the ones that run
npm run build
:The changes in this PR are tested by checking out this branch:
Then run the commands above.
We list the benchmarks by date, because we expect these figures to change as we iterate on this PR.
Reference times
Reference 1: total build time
On the main branch, the total elapsed ("real") time of that last step is 468 s (7 min 48 s). This will serve as a point of reference for all benchmarks.
Reference 2: no parallelism build of the learning MFE
Another interesting point of reference is the time that is needed to build the learning MFE, without parallelism -- that is, without concurrent builds of other MFEs. This is a figure that can be obtained by running:
And then checking the time to build the MFE in the Docker logs:
Here, the reference time is 119.5s.
Single-thread build of the learning app
2025/04/10 Locked cache
We added the following locked cache in the build step:
This causes all builds to run sequentially, and not in parallel. The good thing with this change is that it allows us to no longer customise our Docker builder with
max-parallelism=x
. The only downside is that there might be a drop in performance; but in practice, we don't really observe a noticeable one.2025/04/09 Initial results
All MFEs build under 23s, despite the fact that there are 4 builds in parallel: