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

Save identifier module after first getting #6827

Merged
merged 3 commits into from
Mar 29, 2018

Conversation

Connormiha
Copy link
Member

What kind of change does this PR introduce?
Performance. Cache module identifier after first call.

Did you add tests for your changes?
No

If relevant, link to documentation update:
N/A

Summary

In some plugins we have sort modules function like this:

// From SplitChunksPlugin
const sortByIdentifier = (a, b) => {
	if (a.identifier() > b.identifier()) return 1;
	if (a.identifier() < b.identifier()) return -1;
	return 0;
};

Method identifier() can be run many times while sorting. Each call identifier() calculates identifier from options. We can cache it to avoid repeated calculate.

Does this PR introduce a breaking change?
No

Other information

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

return `multi ${this.dependencies.map(d => d.request).join(" ")}`;
if (this._identifier) return this._identifier;

this._identifier = `multi ${this.dependencies
Copy link
Member

Choose a reason for hiding this comment

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

Could you compute this within the constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do you want to save it inside constructor instead of lazy compute?

Copy link
Member

Choose a reason for hiding this comment

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

We did it this way on other module classes. Moreover, identifier is computed at least once. There is no benefit to compute it lazily.

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 changed it in MultiModule.js

@@ -65,6 +67,7 @@ class ContextModule extends Module {
}

identifier() {
if (this._identifier) return this._identifier;
let identifier = this.context;
Copy link
Member

Choose a reason for hiding this comment

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

Move identifier creation into constructor like with the MultiModule.

Move it into a _createIdentifier() function and call this in the constructor.

@webpack-bot
Copy link
Contributor

@Connormiha Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@sokra sokra merged commit f600ccd into webpack:master Mar 29, 2018
@sokra
Copy link
Member

sokra commented Mar 29, 2018

Thanks

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.

None yet

4 participants