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

optimize alias plugin for huge alias objects #438

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

VincentBailly
Copy link

The alias plugin gets very slow when the webpack config has many aliases.

This PR aims to re-implement the features of the current alias plugin but in a more efficient manner:

  • Create only the minimum amount of closure objects as possible
  • Memoize string operations by running them in the constructor of the plugin

Copy link

linux-foundation-easycla bot commented Dec 10, 2024

CLA Not Signed

@@ -23,6 +22,9 @@ module.exports = class AliasPlugin {
constructor(source, options, target) {
this.source = source;
this.options = Array.isArray(options) ? options : [options];
for (const item of this.options) {
item.nameWithSlash = item.name + "/";
Copy link
Member

Choose a reason for hiding this comment

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

Why we need it?

Copy link
Author

Choose a reason for hiding this comment

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

It's just a memoization so we don't do this concatenation on every resolution, the concatenation creates an object that is short lived, creating work for the garbage collector. By creating the concatenated string once, storing it and reusing it we save the memory overhead of creating many times the same temporary objects.

@alexander-akait
Copy link
Member

Tests are failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants