⚡ Performance: parserOptions.projectService sometimes no longer outperforms parserOptions.project #9571
Description
Overview
When we first started working with the new parserOptions.projectService
(formerly parserOptions.EXPERIMENTAL_useProjectService
), it outperformed equivalent parserOptions.project
setups by ~10-15%. We still sometimes have users report to us that it improved their linting speed. trpc/trpc#5868 is an example of one observation I've made.
However, at some point since then, we've started to notice worse performance of parserOptions.projectService
in our own measurements. https://github.com/typescript-eslint/performance contains tooling to test this. From https://github.com/typescript-eslint/performance/blob/45f77c00c6d4384d466c39e8eb633a76f33dd019/README.md#results:
┌───────┬──────────────────────┬──────────────────────┬──────────────────────┬──────────────────────┐
│ files │ project (even) │ project (references) │ service (even) │ service (references) │
┼───────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┤
│ 128 │ '1.149 s ± 0.030 s' │ '1.135 s ± 0.008 s' │ '1.178 s ± 0.010 s' │ '1.736 s ± 0.012 s' │
│ 512 │ '1.636 s ± 0.009 s' │ '1.656 s ± 0.004 s' │ '1.895 s ± 0.007 s' │ '2.613 s ± 0.020 s' │
│ 1024 │ '2.353 s ± 0.013 s' │ '2.399 s ± 0.016 s' │ '3.130 s ± 0.017 s' │ '4.034 s ± 0.061 s' │
┴───────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┘
Summarizing those results, there seem to be two areas of slowness. Comparing project
to projectService
at ~1024 files:
- Overhead per-file (
(even)
), jumping from ~2.35s to ~3.13s - Overhead switching to project references (
(references)
): jumping from ~2.4s to ~4.0s`
Also note that parserOptions.project
has been in production for years, with many performance optimizations around it. parserOptions.projectService
is very new and not yet stable. There is likely much more "low-hanging fruit" to optimize around parserOptions.projectService
.
We don't yet know whether this is an issue in TypeScript or typescript-eslint. It's probably typescript-eslint.
Relevant past issues:
- Enhancement: Default allowAutomaticSingleRunInference to true #8121
- Bug: ~1.5x slowdown in Sentry codebase from project service #8424
- Bug: Performance regression from #7752 in project service due to changed file name casing #8519
- Bug: using with typescript v5.5 slows down linting by 2.3x #9474 -> perf:
Node.getChildren
speed regression in ts 5.5 when used at very large scale microsoft/TypeScript#59101- Note: the performance issues still show with TypeScript 5.4.5.