question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack 5 app load time slowdown

See original GitHub issue

Bug report

What is the current behavior? Our app’s load time increased significantly when we upgraded to Webpack 5. Target for our app is ES2015.

The JavaScript execution time increased from 1.2s to 1.6s which is pretty significant. We narrowed it down to usage of arrow functions in Webpack 5 internal runtime code.

On using arrow functions in webpack’s internal code, the self time of functions like __webpack_require__ increased significantly. Ideally the self time for functions like this should be close to 0, which it is when it uses vanilla functions.

Webpack 5 by default uses es2015 in its internal code instead of es5 in Webpack 4. So, now the internal code uses () => {} instead of function() {}.

A solution for this would be to change the default value of arrowFunction to false instead of true in https://webpack.js.org/configuration/output/#outputenvironment.

If the current behavior is a bug, please provide the steps to reproduce. I have created a small repo to reproduce this. This repo was generated with gatsby.

Repo: https://github.com/atfzl/webpack5-arrow-function-slowdown

Start the dev server:

  • npm install
  • npm run start

Vanilla function

This will start the dev server at http://localhost:8000 with target: es5. This is our good build. Time to run the JavaScript: 83ms Get the timeline data from Chrome timeline for the app load. Chrome timeline vanilla function.json.zip Screen 2021-04-13 at 18 32 41@2x

Stop the dev server.

Arrow function

Now change the line config.target = [`web`, `es5`] to config.target = [`web`, `es2015`] in node_modules/gatsby/dist/utils/webpack.config.js. Start the dev server again with npm run start.

Go to http://localhost:8000

Now the build served will have arrow functions in the internal code. Time to run the JavaScript: 117ms Get the timeline data from Chrome timeline for the app load. Chrome timeline arrow function.json.zip Screen 2021-04-13 at 18 36 46@2x

The build with arrowFunction is taking 30-40% more time when running JavaScript. I’ve highlighted only one place where options.factory is taking more self time but there are other places as well. Same behavior with the production build as well.

You can also try experimenting with arrow functions and vanilla functions in the browser using local overrides in Chrome.

Changing the vanilla function to fat arrow in framework.js at this place increases the self time of options.factory at the place specified in the above screenshots of timeline. Screen 2021-04-13 at 19 18 57@2x

What is the expected behavior? So, this is not actually a bug with Webpack but the default config provided degrades the performance. I couldn’t find a reason why arrow function is taking much more time. I’ll be opening an issue in V8 to find out the cause.

Other relevant information: webpack version: 5.30.0 Node.js version: 12.18.3 Operating System: macOS Big Sur 11.2.3 Additional tools:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, Nov 11, 2021

You can do it manually, the problems is not for all webpack users, it is also for all js users, and ideally should be fixed in v8, please open a bug in their bug tracker, if we even fix it, other scripts on your package can use it and you will have the same problem

0reactions
webpack-botcommented, Nov 11, 2021

Issue was closed because of inactivity.

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding why our build got 15x slower with Webpack 5
A while back, we encountered an odd problem. All of a sudden, building our front-end went from taking a few seconds to taking...
Read more >
Webpack 5 is consistently ~30% slower for all our packages ...
I have measured with different settings and plugins and Webpack 5 is consistently around at least 30% slower for both our core library...
Read more >
How to boost the speed of your webpack build?
Depending on the machine on which the build was launched, it took between 5 and 12 minutes. It is not possible to have...
Read more >
Build Performance - webpack
This guide contains some useful tips for improving build/compilation performance. General. The following best practices should help, whether you're running ...
Read more >
Cut your Web Application's Load Time in Half with These ...
Cut your Web Application's Load Time in Half with These Webpack Optimization Techniques. The line between native applications and websites ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found