Skip to content

Use a WeakMap instead of mutating objects in NMF - #7348

Merged
sokra merged 1 commit into
masterfrom
refactor/nmf_cache
May 23, 2018
Merged

sokra merged 1 commit into
masterfrom
refactor/nmf_cache

Conversation

@ooflorent

Copy link
Copy Markdown
Contributor

NormalModuleFactory was mutating dependency objects if the unsafeCache option was set. This PR uses a WeakMap to cache dependencies and avoid the mutation (and de-opt).

What kind of change does this PR introduce?

refactoring

Did you add tests for your changes?

no

Does this PR introduce a breaking change?

no

What needs to be documented once your changes are merged?

nothing

@webpack-bot

webpack-bot commented May 19, 2018 •

Copy link
Copy Markdown
Contributor

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

@ooflorent ooflorent changed the title Use a WeakMap instead of mutating objects Use a WeakMap instead of mutating objects in NMF May 19, 2018
@webpack-bot

Copy link
Copy Markdown
Contributor

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

Comment thread lib/NormalModuleFactory.js Outdated
this.context = context || "";
this.parserCache = Object.create(null);
this.generatorCache = Object.create(null);
this.dependencyCache = new WeakMap();

@sokra sokra May 20, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move this to module scope.

For each compilation pass, a new NormalModuleFactory is created.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make more sense to pass as data options so the cache is shared across all compilations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No. Module scope is fine. It's shared between all compilations.

@ooflorent
ooflorent force-pushed the refactor/nmf_cache branch from ad7c7f9 to 8df9f5f Compare May 22, 2018 17:06
@webpack-bot

Copy link
Copy Markdown
Contributor

@ooflorent Thanks for your update.

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

@sokra Please review the new changes.

@sokra

sokra commented May 23, 2018

Copy link
Copy Markdown
Member

Thanks

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.

4 participants