Speed up web vitest suite (~51s -> ~32s): cut per-file import/jsdom overhead - #52
Merged
Conversation
…e import/jsdom overhead The web unit-test suite's cost was dominated by per-file overhead, not test logic: the same module graph (App, mqtt-store, components, bits-ui, the lucide-svelte icon barrel) was re-imported and re-executed, and a fresh jsdom environment was created, for every one of the 94 spec files. Switch the bulk of the suite to vitest's vmThreads pool, which runs each spec file in its own fresh V8 VM context (full per-file isolation, no cross-file state leakage) while reusing the worker's compiled-module cache across files. The three specs that replace the whole window/location global object (not just define a property on it) cannot run under vmThreads, where those globals are non-configurable; they are routed to a standard threads project via test.projects. No test assertions or test code changed. Measured (matched-load A/B, 3 runs each): wall ~51s -> ~32s (-37%) duration ~47s -> ~30s import ~240s -> ~174s environment ~46s -> ~5.4s (-88%) transform ~71s -> ~64s tests ~16s -> ~12s Still 94 files / 1292 tests pass with 0 unhandled errors and 0 stderr noise (verified 5 consecutive runs). The bits-ui scroll-lock drain in tests/setup.js (PR #46) and the clean output (PR #48) are preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The web unit-test suite's wall-clock was dominated by per-file overhead, not test logic. The same module graph (
App,mqtt-store, components,bits-ui, thelucide-svelteicon barrel) was re-imported and re-executed, and a fresh jsdom environment created, for every one of the 94 spec files. Actual test execution was already cheap (~16s).This PR switches the bulk of the suite to Vitest's
vmThreadspool, which runs each spec file in its own fresh V8 VM context (full per-file isolation, no cross-file state leakage) while reusing the worker's compiled-module cache across files. That collapses the dominant import/environment cost. No test assertions or test code changed; the only file touched isweb/vitest.config.js.Levers evaluated
isolate: false(threads)vi.mock('api.js')of the mqtt-store leaks across files. Exactly the cross-file coupling the brief warns about.deps.optimizer.web(lucide / multi-dep)pool: 'threads'(whole suite)forksbaseline for this jsdom-heavy workload.pool: 'vmThreads'(applied)Under
vmThreadsthe VM'swindow/locationglobals are non-configurable, so the 3 specs that replace the wholewindow/locationobject (api-base-derivation,connection-status,slash-commands) are routed to a standardthreadsproject viatest.projects. Specs that only define a property onwindow(matchMedia, innerWidth, etc.) run fine undervmThreads. A future spec that reassigns the whole global fails loudly undervmThreads, never silently.Before -> after (matched-load A/B, 3 runs each)
The dominant saving is the per-file jsdom environment cost (-88%) plus reduced module re-import.
Stability gate (5 consecutive runs)
All 5 runs: exit 0, 94 files / 1292 tests passed, 0 unhandled errors, 0 stderr lines.
The bits-ui scroll-lock drain in
tests/setup.js(PR #46) and the clean 0-unhandled / 0-stderr output (PR #48) are preserved.pnpm --dir web buildstays green. No skips/excludes added; same 1292 assertions.🤖 Generated with Claude Code