Skip to content

perf(test): share one PGlite VM across tests (core 48s→28s, api 26s→5.5s) - #67

Closed
jherr wants to merge 3 commits into
feat/capability-seamsfrom
perf/test-shared-pglite
Closed

jherr wants to merge 3 commits into
feat/capability-seamsfrom
perf/test-shared-pglite

Conversation

@jherr

@jherr jherr commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

What

Cuts test-suite wall-clock by sharing one PGlite VM across tests instead of booting a fresh one per defineCms.

Why (measured, not guessed)

Benchmarked PGlite on this machine:

  • PGlite.create() ≈ 400ms every instance (WASM VM boot + baked Postgres catalog load; ~150ms of that is one-time WASM compile per process).
  • CMS migrations on top ≈ 13ms.

So the flaky/slow CI wasn't schema work or our code — it was booting a 400ms VM for every defineCms across ~54 test files, serially (VITEST_MAX_WORKERS=1). A pre-migrated snapshot wouldn't help; the cost is per-VM-boot.

How

@tanstack/cms-store-postgres/testing (the vitest setupFiles that restores the embedded engine for tests) now:

  • opens one in-memory PGlite VM per process (the 400ms is paid once), and
  • gives each config an isolated schema via a table prefix keyed by its resolved dataDir.

This reproduces the old embedded default's semantics exactly — same dataDir shares a schema (so close + re-defineCms still sees its data, which the cross-restart tests rely on), distinct dataDirs are isolated — so no test files changed. createPostgresStorage already skips pool.end() for a passed-in pool, so the shared VM survives per-config storage.close().

app/base keeps real on-disk persistence via a new ./testing-disk variant: its recover-owner test spawns a subprocess that reads the database file, which an in-memory VM can't serve.

Result

suite before after
@tanstack/cms-core ~48s ~28s
@tanstack/cms-api ~26s ~5.5s

Full test:lib green across all 24 projects; core 661/661; sherif clean. Beyond the speedup, the headroom directly relieves the 20s-per-test timeout flakes.

Notes

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0054252

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/cms-api

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-api@67

@tanstack/cms-cli

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-cli@67

@tanstack/cms-client

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-client@67

@tanstack/cms-compat-wp

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-compat-wp@67

@tanstack/cms-connect-atproto

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-connect-atproto@67

@tanstack/cms-migrate-wp

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-migrate-wp@67

@tanstack/cms-skills

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-skills@67

@tanstack/cms-core

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-core@67

@tanstack/cms-media-s3

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-media-s3@67

@tanstack/search-ai

npm i https://pkg.pr.new/TanStack/cms/@tanstack/search-ai@67

@tanstack/search-cms

npm i https://pkg.pr.new/TanStack/cms/@tanstack/search-cms@67

@tanstack/search-core

npm i https://pkg.pr.new/TanStack/cms/@tanstack/search-core@67

@tanstack/search-headless

npm i https://pkg.pr.new/TanStack/cms/@tanstack/search-headless@67

@tanstack/search-ui-react

npm i https://pkg.pr.new/TanStack/cms/@tanstack/search-ui-react@67

@tanstack/cms-store-postgres

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-store-postgres@67

@tanstack/cms-ui-dom

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-ui-dom@67

@tanstack/cms-ui-react

npm i https://pkg.pr.new/TanStack/cms/@tanstack/cms-ui-react@67

commit: 0054252

jherr and others added 2 commits December 2, 2026 17:32
Measured: a PGlite VM costs ~400ms to boot (WASM + baked catalog) while the CMS
migrations on top are only ~13ms — so the test cost was dominated by booting a
fresh VM per `defineCms`, not by schema work. The `@tanstack/cms-store-postgres/testing`
setup now shares ONE in-memory VM per process and gives each config an isolated
schema via a table prefix keyed by its resolved data dir. This mirrors the old
embedded default's semantics exactly (same dataDir shares — so close+reopen
still sees its data — distinct dataDirs isolate), but pays the 400ms boot once
instead of per config. A passed-in pool isn't closed by storage.close(), so the
shared VM survives per-config teardown.

Result: core 48s→28s, api ~26s→5.5s; no test changes needed.

app/base keeps on-disk persistence via the new `./testing-disk` variant — its
recover-owner test spawns a subprocess that reads the database file, which an
in-memory VM can't serve.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jherr
jherr force-pushed the perf/test-shared-pglite branch from 85acc20 to 0ef0fae Compare December 3, 2026 01:33
@jherr

jherr commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #68, which flattens this stack into a single PR against main.

@jherr jherr closed this Dec 3, 2026
@jherr
jherr deleted the perf/test-shared-pglite branch December 3, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant