Skip to content

Performance Issue - 50% of time spent inside statSync #3597

Closed
@urish

Description

@urish

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Running jest with about 100 tests take around 10-14 seconds on my machine. After doing some profiling, I figured out it calls fs.statSync() about 150,000 times (so about 1,500 times per single test), and spends there about 6.5 seconds, which is roughly half of the run time. All these calls are initiated by jest-resolve (which eventually uses the resolve package).

Using jest v20.0.1, jest-resolve 20.0.1.

Here are my benchmark results:

Test Suites: 14 passed, 14 total
Tests:       3 skipped, 107 passed, 110 total
Snapshots:   0 total
Time:        13.784s
Ran all test suites.
Total statSync calls: 152244
Total time spent (ms): 6916.388558894396

How did I perform the benchmark?

  1. I replaced node_modules/jest-resolve/node_modules/resolve/lib/sync.js with this instrumented version. I instrumented the isFile() method to figure out how many times it is called and time spent inside.
  2. I ran jest --runInBand

Also tried to disable cache, but the method was still called ~ 150,000 times.

finally, here is my jest configuration:

  "jest": {
    "preset": "jest-preset-angular",
    "rootDir": "app",
    "setupTestFrameworkScriptFile": "<rootDir>/setupJest.ts",
    "testRegex": "\\.spec\\.(ts)$",
    "transform": {
      "^.+\\.(ts|js|html)$": "<rootDir>/../node_modules/jest-preset-angular/preprocessor.js"
    },
    "globals": {
      "__TS_CONFIG__": "app/tsconfig.spec.json",
      "__TRANSFORM_HTML__": true
    }
  }

If needed, I would love to provide more feedback or dig into it further - but please provide me some pointers where to dig.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions