vitest: Performance regression between 0.33.0 and 0.34.X

Describe the bug

The same test suite:

  • With version 0.33.0: yarn test 202.70s user 31.13s system 634% cpu 36.857 total
  • With version 0.34.0: yarn test 293.07s user 42.05s system 311% cpu 1:47.58 total
  • With version 0.34.1: yarn test 291.66s user 43.37s system 306% cpu 1:49.16 total

Keywords: performance, time

Reproduction

I can’t publish all the test we have in the private project, but this is the configuration we use:

/// <reference types="vitest" />

import path from 'path';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';

import tsconfigPaths from 'vite-tsconfig-paths';
import pkg from './package.json';

export default defineConfig({
    plugins: [
        react(),
        vanillaExtractPlugin(),
        tsconfigPaths(),
        dts({
            entryRoot: './src',
            exclude: [
                'node_modules',
                'dist',
                '**/*.stories.*',
                '**/*.test.*',
                '**/*.test-acceptance.*',
            ],
        }),
        {
            name: 'remove-ensure-watch-plugin',
            enforce: 'post',
            configResolved: config => {
                // https://github.com/vitejs/vite/issues/13342
                (config as any).plugins = config.plugins.filter(
                    p => p?.name !== 'vite:ensure-watch'
                );
            },
        },
    ],
    build: {
        emptyOutDir: false,
        lib: {
            entry: 'src/index.ts',
            formats: ['es'],
            fileName: 'index',
        },
        sourcemap: true,
        rollupOptions: {
            external: [/@private/, 'classnames', 'react', 'react-dom'],
            output: {
                manualChunks: Object.fromEntries(
                    Object.keys(pkg.dependencies)
                        .filter(
                            dependency => !dependency.startsWith('@private')
                        )
                        .map(dependency => [dependency, [dependency]])
                ),
            },
        },
    },
    test: {
        globals: true,
        environment: 'jsdom',
        include: ['src/**/*.test.{ts,tsx}'],
        setupFiles: './src/setupTests.tsx',
        alias: [
            {
                find: '@private-app/api',
                replacement: path.resolve(__dirname, '../api/src'),
            },
            {
                find: /@private-app\/core\/(.+)/,
                replacement: path.resolve(__dirname, '../core/src/$1'),
            },
        ],
    },
});

With the exact same sourcecode, just upgrading the vitest dependency from 0.33.0 to 0.34.1, the test time grows significantly This is one of the runs inside the CI Linux agent: image

System Info

Reproduced in:
* MacBook Pro with macOS 13.1.
* Linux virtual machine inside TeamCity CI agent.

Used Package Manager

yarn

Validations

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 5
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

If you add test.testTransformMode.ssr: ['**/*'] does it return to the previous speed?

This should be fixed in Vitest 1.1.2.

Incase it can be of any help:

0.32.4

image

0.34.6 (no SSR - default)

image

0.34.6 (SSR)

image

Not helpful since I don’t see the code and config.

I’ve upgraded vitest to the latest version and I can also confirm that ghe fix works, thank you so much for the effort!

@sheremet-va It works amazingly well! Thanks and congrats!

Hey @sheremet-va

Thanks for the advice to disable the testTransformMode ssr transform - it busts the test speed!

But I am struggling to understand how exactly one would disable vite:react-babel and vite:react-refresh? I can only disable them if I call react({ babelrc: false }) but then my entire build does not work. Let me know if you need any additional details 🙏

Vitest passes down mode as test, and also sets VITEST env variable, so you can conditionally remove it:

export default defineConfig(({ mode }) => {
  return {
    plugins: mode === 'test' ? [] : [react()]
  }
})

Or:

export default defineConfig(({ mode }) => {
  return {
    plugins: process.env.VITEST ? [] : [react()]
  }
})

Any update here? still experiencing this

Can you send your resolved config that is printed with DEBUG=vite:config vitest?