Harmony imports/exports slow down rebuilds

Do you want to request a feature or report a bug?
I want to discuss webpack behavior that may either be a bug or end up being a feature request.

What is the current behavior?
The number of harmony import/exports in an application increases rebuild time all code changes, even trivial ones that do not affect imports/exports.

This can be seen in CPU profiles of rebuilds, in applyPluginsBailResult1 (under seal). The more harmony exports there are in an application, the more time is spend on this phase checking each one.

There is a reproduction below, where this can be see. The reproduction contains two precompiled Angular applications: one in JIT mode and one in AOT mode. In Angular, AOT mode generates more files than JIT mode. These files contain more harmony exports.

The JIT application rebuild spends 70.5/66.0 ms in this phase, whereas the AOT application takes
253/200.1 ms. Larger applications spend more time in this phase, even on rebuilds where no
import or export was altered (e.g. adding console.log(1);).

Here is a screenshot of the applyPluginsBailResult1 phase in the JIT application:
image

And here is the same for the AOT application:
image

The 160ms difference might not seem that drastic, but this is just a toy application. In bigger applications
this phase takes much longer.

In the case of Angular.io, a full rebuild in AOT mode total 4.5s, of which around 1.3s is spent on applyPluginsBailResult1. By comparison, the same code change takes only some 0.15s on the JIT (less imports/exports) version.

CPU profile of Angular.io JIT rebuild:
image

CPU profile of Angular.io AOT rebuild:
image

I understand harmony imports/exports enable better optimizations and need to be checked because of that, but this seems a very steep increase in rebuild time that is outside of the control of loader/plugin authors. Perhaps there is a way to reduce the time spent on this phase.

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

A reproduction can be found in https://github.com/filipesilva/webpack-harmony-exports, together with CPU profiles for the seen behaviour.

Please note there are no loaders, all code is ES5 with ES2015 imports/exports.

What is the expected behavior?

Rebuilds that do not affect import/exports should not incur such a significant rebuild time due to harmony import/export checks.

If this is a feature request, what is motivation or use case for changing the behavior?

Rebuild speed is of utmost importance for application development.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Chrome 61, node v6.11.1, webpack 3.6.0, Windows 10

/cc @d3viant0ne

Author: Fantashit

2 thoughts on “Harmony imports/exports slow down rebuilds

Comments are closed.