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

[build-report] Optimise build-report to prevent memory hog over long running builds #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yoannmoinet
Copy link
Member

What and why?

Running a devserver with webpack/rspack would often (always) end up with a RangerError: Maximum call stack size exceeded error.

image

How?

The build-report was filling arrays over and over, with each build increasing their size.

Now the build-report cleans between builds, and keep state in a more efficient way (using Set and Map).

The indexation of modules doesn't log warnings anymore, we mitigate the previous duplication issues by merging differences into the previously indexed module.

Testing covers these changes and remain ✅

@yoannmoinet yoannmoinet marked this pull request as ready for review March 21, 2025 14:57
@yoannmoinet yoannmoinet requested review from jakub-g, elbywan and Ayc0 March 21, 2025 15:57
Comment on lines +76 to +78
inputs = [];
outputs = [];
entries = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we prefer to do = [] or .length = 0? (to use the same array, but clear it, like what we do with the sets .clear() as we aren't redefining new ones with moduleIndex = new Set())

Copy link
Member Author

Choose a reason for hiding this comment

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

I was using .length = 0 but I kind of found it a bit hacky and not super explicit.

From what I read online, it's seemingly the same performance either = [] or .length = 0, so I went with the most explicit and comprehensible one.

// We know it's not a map, so we cast it.
entryInputs.push(...(outputFound.inputs as Input[]));
for (const input of outputFound.inputs as Input[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is the cast necessary here?

Copy link
Member Author

@yoannmoinet yoannmoinet Mar 21, 2025

Choose a reason for hiding this comment

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

In the case of sourcemaps, file.inputs are Outputs as sourcemaps are built out of both Output and Input type of files.

So since I'm checking it's not a sourcemaps earlier, I'm casting it to make the rest of code type error free.

Very much looking for a better way.

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