perf: vitest threads pool + Dockerfile pnpm cache mount #66

Merged
michal merged 1 commits from perf/vitest-threads-and-docker-pnpm-cache into main 2026-04-27 16:07:06 +00:00
2 changed files with 30 additions and 4 deletions
Showing only changes of commit 18245be0c1 - Show all commits

View File

@@ -1,3 +1,9 @@
# syntax=docker/dockerfile:1.6
# `# syntax=...` enables BuildKit's --mount feature on the builder so we can
# share the pnpm content-addressed store across image builds. Without it the
# next two RUN steps fall back to plain mode and the cache mount is ignored
# (build still works, just slower).
# Stage 1: Build TypeScript # Stage 1: Build TypeScript
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
@@ -12,8 +18,12 @@ COPY src/db/package.json src/db/tsconfig.json src/db/
COPY src/shared/package.json src/shared/tsconfig.json src/shared/ COPY src/shared/package.json src/shared/tsconfig.json src/shared/
COPY src/web/package.json src/web/tsconfig.json src/web/ COPY src/web/package.json src/web/tsconfig.json src/web/
# Install all dependencies # Install all dependencies. The cache mount keeps pnpm's CAS store warm
RUN pnpm install --frozen-lockfile # across builds: only newly-changed packages get downloaded; everything
# else hardlinks from the cache. Drops install from ~60s to <5s on a
# warm cache. `--frozen-lockfile` still guarantees lockfile fidelity.
RUN --mount=type=cache,id=pnpm-store-mcpd-builder,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile
# Copy source code # Copy source code
COPY src/mcpd/src/ src/mcpd/src/ COPY src/mcpd/src/ src/mcpd/src/
@@ -42,8 +52,11 @@ COPY src/mcpd/package.json src/mcpd/
COPY src/db/package.json src/db/ COPY src/db/package.json src/db/
COPY src/shared/package.json src/shared/ COPY src/shared/package.json src/shared/
# Install all deps (prisma CLI needed at runtime for db push) # Install all deps (prisma CLI needed at runtime for db push). Same
RUN pnpm install --frozen-lockfile # cache-mount trick as the builder stage; separate cache id so the two
# stages don't compete for the same lock.
RUN --mount=type=cache,id=pnpm-store-mcpd-runtime,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile
# Copy prisma schema and generate client # Copy prisma schema and generate client
COPY src/db/prisma/ src/db/prisma/ COPY src/db/prisma/ src/db/prisma/

View File

@@ -1,8 +1,21 @@
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
import { availableParallelism } from 'node:os';
// Default vitest's pool to ~half the CPU threads we have. The previous
// implicit default left this 64-thread workstation at ~10% utilization
// during `pnpm test:run`. Half is a soft cap that stays kind to laptops
// (8-thread → 4 workers) while letting beefy hosts push closer to the
// box's actual capacity. Override at run time with VITEST_MAX_THREADS.
const cores = availableParallelism();
const maxThreads = Number(process.env['VITEST_MAX_THREADS'] ?? Math.max(2, Math.floor(cores / 2)));
export default defineConfig({ export default defineConfig({
test: { test: {
globals: true, globals: true,
pool: 'threads',
poolOptions: {
threads: { maxThreads, minThreads: 1 },
},
coverage: { coverage: {
provider: 'v8', provider: 'v8',
reporter: ['text', 'json', 'html'], reporter: ['text', 'json', 'html'],