You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our large monorepo, the collect time is by far the largest. It would be nice if there were a reporter that would show how long was spent on collect in a more granular manner, such as every file Vitest has processed.
Suggested solution
vitest run --reporter=collect-time could report every imported file with the total time spent importing it.
Collecting time of every file that was loaded sounds a bit extreme. Currently Vitest tracks only the time the whole test file took to load. Using custom reporter you can see test file specific times:
// collection-reporter.tsimport{typeReporter}from"vitest/reporters";exportdefaultclassCollectionReporterimplementsReporter{onTestRunEnd(testModules: Parameters<Reporter["onTestRunEnd"]>[0]){for(consttestModuleoftestModules){console.log(`${testModule.moduleId} took ${testModule.diagnostic().collectDuration} ms to collect`);}}}
Well, it's already transforming every file loaded, so tracking how long each import took is a very very small amount of time, proportionally @AriPerkkio. I'm not looking for test file times, but whycollect is so large.
Reacted by Ari Perkkiö, Valentin Semirulnik and Kirill Groshkov
Hi, just wanted to add that, as another maintainer of a relatively large monorepo, this would be extremely useful. We're currently experiencing the same, where collect is order of magnitudes slower than the actual tests, mostly because barrel files were used earlier and they nuke performance 😅
Reacted by Valentin Semirulnik and Kirill Groshkov
What should be the threshold for showing files? It feels like this highly depends on the project, so should be configurable. But a good default is really important. Spitballing... >500ms total time / >100ms self time perhaps?
It should probably be self-time mostly, but should we also report slow total times?
verbose mode - printing a list of every imported file after every test is extreme I think, there could be hundreds of files imported per test file. If not, what should verbose print? > slowThreshold files after each test?
Is this data useful for all projects? It's not super useful for Vitest itself it seems since it doesn't have major slow dependencies. I'd be worried about unilaterally introducing it for the default reporter for all projects, but that's your maintainers' calls.
Reacted by Kirill Groshkov
Reacted by Fredrik A. Madsen-Malmo and Kirill Groshkov
I expected there to be an option like slowTestThreshold, and then show everything that is above that treashold.
I think maybe by default we can print a warning like "Vitest found <n> of files that took longer than <ms> during collection.". In watch mode we add "Press <button> to show the list of them" and in run mode we can say "To print the list of files, enable the <name> config option".
verbose mode - printing a list of every imported file after every test is extreme I think, there could be hundreds of files imported per test file. If not, what should verbose print? > slowThreshold files after each test?
I don't think we should print every file, it should respect the config treashold.
Another thing that might be interesting is incorporating this in UI, but that's a big task.
I expected there to be an option like slowTestThreshold, and then show everything that is above that treashold.
Maybe slowCollectThreshold? This reporting feature is still about just collect phase, not about test running phase, right?
I think maybe by default we can print a warning like "Vitest found <n> of files that took longer than <ms> during collection.".
And it should be possible to disable the feature by providing value of 0 in the config.
In watch mode we add "Press <button> to show the list of them" and in run mode we can say "To print the list of files, enable the <name> config option".
Is there more progress on this?
Can I help somehow? I'm very interested in debugging "collect time performance" for our projects, and currently writing a lot of my own debugging scripts. But sounds like this issue is ahead of me, and maybe needs some last pushes to be useful? 🙏
Activity
AriPerkkio commentedon May 25, 2025
Collecting time of every file that was loaded sounds a bit extreme. Currently Vitest tracks only the time the whole test file took to load. Using custom reporter you can see test file specific times:
abrenneke commentedon May 25, 2025
Well, it's already transforming every file loaded, so tracking how long each import took is a very very small amount of time, proportionally @AriPerkkio. I'm not looking for test file times, but why
collectis so large.FredrikAugust commentedon May 26, 2025
Hi, just wanted to add that, as another maintainer of a relatively large monorepo, this would be extremely useful. We're currently experiencing the same, where collect is order of magnitudes slower than the actual tests, mostly because barrel files were used earlier and they nuke performance 😅
abrenneke commentedon May 29, 2025
Now that #8027 is merged 🎉 let's talk about how we'd like to integrate it with reporters @sheremet-va @hi-ogawa @AriPerkkio
Our options seem to be:
Could also do both 2 and 3?
Open questions for 3 are:
verbosemode - printing a list of every imported file after every test is extreme I think, there could be hundreds of files imported per test file. If not, what should verbose print?> slowThresholdfiles after each test?sheremet-va commentedon May 30, 2025
I expected there to be an option like
slowTestThreshold, and then show everything that is above that treashold.I think maybe by default we can print a warning like "Vitest found
<n>of files that took longer than<ms>during collection.". In watch mode we add "Press<button>to show the list of them" and in run mode we can say "To print the list of files, enable the<name>config option".I don't think we should print every file, it should respect the config treashold.
Another thing that might be interesting is incorporating this in UI, but that's a big task.
AriPerkkio commentedon Jun 3, 2025
Maybe
slowCollectThreshold? This reporting feature is still about justcollectphase, not about test running phase, right?And it should be possible to disable the feature by providing value of
0in the config.Sounds perfect. This should also be mentioned on https://vitest.dev/guide/profiling-test-performance.html guides.
kirillgroshkov commentedon Jul 9, 2025
Is there more progress on this?
Can I help somehow? I'm very interested in debugging "collect time performance" for our projects, and currently writing a lot of my own debugging scripts. But sounds like this issue is ahead of me, and maybe needs some last pushes to be useful? 🙏
hi-ogawa commentedon Jul 9, 2025
@kirillgroshkov The stats is available in reporter API. The primitive example is found here #8027 (comment) https://stackblitz.com/edit/vitest-dev-vitest-335d17yc?file=vite.config.ts
sheremet-va commentedon Nov 24, 2025
You can also use OpenTelemetry traces to see how long it takes to load modules. They are called
vitest.module.inlineandvitest.module.external.