webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Hoist RegExp Literals in SourceMapDevToolPlugin

Open TheLarkInn opened this issue 2 years ago • 8 comments

Bug report

What is the current behavior? The use of RegExp literals create unnecessary object references/allocations especially in iterated hot paths like SourceMapDevToolPlugin. We should hoist these to the top of file and give them useful names so people understand what the heck they do.

If the current behavior is a bug, please provide the steps to reproduce. Some Examples:

Mapping over a RegExp literal: https://github.com/webpack/webpack/blob/3ad4fcac25a976277f2d9cceb37bc81602e96b13/lib/SourceMapDevToolPlugin.js#L419

Big Async ForEach Statement with multiple RexExp Literal statements: https://github.com/webpack/webpack/blob/3ad4fcac25a976277f2d9cceb37bc81602e96b13/lib/SourceMapDevToolPlugin.js#L384-L551

What is the expected behavior? Less memory allocation, less garbage collection triggered.

Happy to PR this. There are quite a few of these examples still lying around webpack that should be cleaned up but I'll start with this.

TheLarkInn avatar Apr 26 '22 16:04 TheLarkInn

This makes sense to me - I wonder if you have any perf traces or anything that could show any marked improvement from this change?

markjm avatar Apr 26 '22 23:04 markjm

This makes sense to me - I wonder if you have any perf traces or anything that could show any marked improvement from this change?

I'll try and find something to show. I won't have before and after, however I'll be able to show the hot path from a memory profiling trace.

TheLarkInn avatar Apr 28 '22 20:04 TheLarkInn

image

@markjm Here is an example of mem allocation hotpath if this helps. This tree is during the forEach calls referenced in the PR.

TheLarkInn avatar Apr 28 '22 22:04 TheLarkInn

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

webpack-bot avatar Jul 29 '22 07:07 webpack-bot

bump

alexander-akait avatar Jul 29 '22 11:07 alexander-akait

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

webpack-bot avatar Nov 13 '22 01:11 webpack-bot

@TheLarkInn Do we still need it?

alexander-akait avatar Mar 07 '23 18:03 alexander-akait

I'll address PR comments and then we can reopen and close once we merge it.

TheLarkInn avatar Mar 07 '23 23:03 TheLarkInn