Skip to content

[Bug]: performance bottleneck in loader-runner resolver creation #9399

@dinofx

Description

@dinofx

System Info

macOS

Details

I have a build that compiled a few thousand modules in 9 seconds. About 5% of the build time is wasted in creating the loaderContext's resolve function (which is never called in my case). The slow code is the first line of:

const resolver = compiler._lastCompilation!.resolverFactory.get("normal");
loaderContext.resolve = function resolve(context, request, callback) {
resolver.resolve({}, context, request, getResolveContext(), callback);
};

Image

To confirm the issue, I tried hacking my installed index.js file (version 1.2.5) so that resolver was only created if called:

  let resolver;
  loaderContext.resolve = function resolve2(context3, request, callback) {
    if (!resolver)
      resolver = compiler._lastCompilation.resolverFactory.get("normal");
    resolver.resolve({}, context3, request, getResolveContext(), callback);
  };

With the above change, the overall time for the runLoaders function decreased by roughly the 438ms shown above.

Reproduce link

No response

Reproduce Steps

Run a build with RSPACK_PROFILE=JSCPU, and then look in the timing information for the runLoaders function.

Currently:

Image

With the "fix" above:

Image

Metadata

Metadata

Assignees

Labels

pending triageThe issue/PR is currently untouched.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions