DEV Community

Cover image for ๐Ÿš€ 22s to 4s: How AI Fixed Our Vitest Performance
56kode
56kode

Posted on

๐Ÿš€ 22s to 4s: How AI Fixed Our Vitest Performance

Running unit tests shouldn't feel like a coffee break. But on our main frontend project, that's exactly what happened. Every time we launched a single test file, we had to wait over 20 seconds before the first test even started.

We tried the usual fixes: tweaking the vitest.config.ts, isolating threads, optimizing mocks... Nothing worked. The bottleneck wasn't in the configurationโ€”it was deep in our architecture.

In this article, I share how we used Gemini 3 Pro to identify and fix the issue, dividing our local test startup time by 5 and saving 15 minutes on every CI pipeline run.

What you'll learn in the full post

โœ… The "God Module" Anti-Pattern: How importing a single utility can silently load your entire application.

โœ… AI-Assisted Debugging: Why Gemini 3 Pro succeeded where other models failed to diagnose architectural flaws.

โœ… The Refactoring Strategy: How we decoupled our Redux Store and Modal System to stop the dependency chain.

โœ… Concrete Results: The before/after metrics that proved the fix worked.

A taste of the problem

The issue wasn't the test execution speed itself, but the transform and collect phases of Vitest.

Here is what running a single, isolated test looked like:

Test Files 1 passed (1)
Tests 3 passed (3)
Start at 09:32:08
Duration 22.53s (transform 12.53s, collect 21.47s, tests 323ms)
Enter fullscreen mode Exit fullscreen mode

Notice the disconnect? 323ms to run the test, but 21+ seconds to prepare it.

The culprit? Our component imports were triggering a chain reaction. For example, importing a modal provider for a test was inadvertently importing every single modal in the application (Billing, Planning, Resources...), forcing Vitest to parse thousands of files unnecessarily.

The Fix

We used AI to refactor our architecture, splitting "heavy" UI providers from "light" contexts used in tests.

The result speaks for itself:

Duration 4.29s (transform 1.90s, setup 189ms, collect 3.44s)
Enter fullscreen mode Exit fullscreen mode

If you are struggling with slow Vitest startup times or want to see how AI can help with complex architectural refactoring, check out the full story.

๐Ÿ‘‰ Read the full article here: How Gemini 3 Pro cut our pipeline time in half

Top comments (0)