perf(ci): Go build-test takes 12 to 19 minutes as SQLite race tests scale
Bug
The required GitHub Actions check Go / build-test (pull_request) now takes roughly 12 to 19 minutes on successful pull requests. The full race-enabled backend test step is the critical path, particularly backend/internal/storage/sqlite.
Reported by: Harshit Singh Bhandari
Analyzed against: 24e101914976a14145d7302f49626db3541ef8b5
Confidence: High. The workflow, job logs, package timings, historical runs, test fixture path, and migration serialization were traced directly.
Priority: P1. This delays every backend pull request and has steadily regressed, but does not break correctness.
Current workflow
.github/workflows/go.yml runs this sequence on ubuntu-latest:
actions/checkout@v4actions/setup-go@v5usingbackend/go.mod, withcache: false- Formatting check
go build ./...go vet ./...go test -race -timeout=15m ./...
There is no wrapper script, artifact upload, or large log-processing step. The 15 minute package timeout was added in cf350730 after the SQLite package approached Go's default 10 minute timeout.
Measured impact
A sample of 17 successful pull request runs from 2026-09-06 17:47 UTC through 2026-09-07 15:15 UTC showed:
| Measurement | Minimum | Median | Approximate p90 | Maximum |
|---|---|---|---|---|
Whole build-test job |
11m40s | 15m13s | 18m01s | 18m40s |
Test step |
10m42s | 14m04s | 16m43s | 17m21s |
The test step consumes about 92 percent of median job time.
Representative runs:
| Run | Started | Job | Setup | Build | Vet | Test | SQLite package |
|---|---|---|---|---|---|---|---|
| Fast successful run | 2026-09-07 13:04 UTC | 11m40s | 10s | 28s | 9s | 10m42s | 448.732s |
| Slow successful run | 2026-09-07 15:03 UTC | 18m40s | 15s | 42s | 14s | 17m21s | 758.741s |
| Another slow run | 2026-09-07 15:13 UTC | 17m39s | 12s | 40s | 13s | 16m27s | 714.313s |
This is a sustained regression, not a one-off slow runner:
| Date and run | Whole job | Test step | SQLite package |
|---|---|---|---|
| 2026-07-07 | 2m30s | 1m46s | 3.499s |
| 2026-08-07 | 4m23s | 3m27s | 66.263s |
| 2026-08-26 | 9m05s | 8m04s | 293.734s |
Across corresponding commits, backend test files grew from 167 to 329 to 444 to 546, SQLite test files from 10 to 20 to 33 to 45, and migrations from 21 to 63 to 93 to about 112. The SQLite package grew much faster than the suite itself.
Root cause
1. Full race instrumentation is the dominant multiplier
On current main, a local comparison of only the two hottest packages with a warm compilation cache produced:
| Command | Wall time | SQLite | Store |
|---|---|---|---|
go test -count=1 ./internal/storage/sqlite ./internal/storage/sqlite/store |
22.93s | 12.184s | 7.903s |
go test -race -count=1 ./internal/storage/sqlite ./internal/storage/sqlite/store |
597.59s | 577.884s | 399.236s |
Race instrumentation increased wall time by about 26 times and reported package time by roughly 47 to 50 times. Full race coverage is valuable and should be preserved. The suite and fixtures need to make that coverage affordable.
2. Test fixtures repeatedly enter serialized migration work
backend/internal/storage/sqlite/db.go makes every sqlite.Open acquire gooseMu, run the migration-history repair and preparation probes, call goose.Up, and reconcile schema. Current main contains about 112 migration files.
The SQLite tree has 319 tests, roughly 83 open helper calls, and only 9 t.Parallel() calls. Production migration work is intentionally serialized because Goose uses package-level globals.
backend/internal/storage/sqlite/sqlitetest/sqlitetest.go builds one migrated database template with sync.Once, but each clone still calls sqlite.Open. The store suite invokes its test store helper roughly 171 times, so already-current clones repeatedly re-enter Goose and schema repair checks. Dedicated migration compatibility tests also perform many real opens, usually serially.
3. Runner variability amplifies the structural cost
Recent fast and slow runs used distinct GitHub-hosted x64 runners but the same ubuntu-24.04 image version 20260831.293.1. Build, vet, SQLite, store, chat, usage, controller, and spec generation times all move together by roughly 1.5 to 1.7 times. That is consistent with runner CPU or I/O variability, not one intermittent test.
4. Cold caches and duplicate Go toolchain setup add smaller fixed costs
setup-go caching is explicitly disabled. A representative build emitted 45 dependency download lines within about 2.46 seconds, then spent most of its 33 seconds compiling.
Setup installs Go 1.25.7 from backend/go.mod, but root go.work declares Go 1.26.5. GOTOOLCHAIN=auto then downloads Go 1.26.5 as a second toolchain. This costs roughly 5 to 10 seconds, not the multi-minute regression.
5. Actions bookkeeping is negligible
Representative logs are about 469 lines and 55 KB. Post-job cleanup takes 2 to 3 seconds. There are no artifacts.
Recommended optimization order
-
Measure individual SQLite costs first. Capture
go test -race -jsontimings and count productionOpencalls per test. Benchmark-p=1,-p=2, and-p=4to determine whether package concurrency is causing runner thrash. -
Open known-current cloned test databases without rerunning migrations. Give
sqlitetesta test-only path that establishes the normal writer and reader pools against its verified template without running Goose and repair checks again. Keep every migration compatibility test on the productionsqlite.Openpath. Assert the cloned schema version and isolation. Estimated pull request wall-time reduction: 4 to 10 minutes, depending on contention. -
Reduce repeated migration setup without reducing coverage. Reuse immutable historical schema snapshots where multiple cases start from the same version, consolidate compatible table-driven cases, and measure each change. Preserve tests for clean install, supported historical upgrades, burned or renumbered histories, idempotent reopen, rollback where supported, and schema reconciliation.
-
Preserve full race coverage while parallelizing its delivery. If fixture work is insufficient, shard stable migration test groups or move the complete race suite into parallel jobs. Do not drop packages from race coverage. Sharding may save 3 to 8 minutes of wall time but increases runner minutes and setup duplication.
-
Enable correctly keyed Go caching. Configure
actions/setup-gowith explicit dependency paths forbackend/go.sumand workspace inputs. Use-count=1if all tests must execute while still retaining compilation-cache benefits. Expected warm saving: 30 to 90 seconds. Measure hit rate, restore time, save time, and cache size. -
Align the installed toolchain with
go.work. Avoid installing 1.25.7 and then automatically downloading 1.26.5. Expected saving: 5 to 10 seconds. -
Only then evaluate larger runners. First use the
-pmeasurements to establish whether more CPU improves the critical path enough to justify cost.
Acceptance criteria
- Full backend race coverage remains in CI. Optimizing or sharding it must not silently exclude packages.
- Migration compatibility coverage remains explicit and continues to exercise production
sqlite.Open. - Known-current test clones do not rerun the full migration and repair path.
- Compare at least 10 successful pull request runs before and after. Report median and p90
build-test,Test, SQLite, and store timings. - Target a median pull request
build-testtime below 5 minutes, with no package approaching the test timeout.
Related
- PR #3669 introduced migrated SQLite test fixtures and reported reducing a full local race run to 2m06s. Continued suite growth has erased that gain, and each cloned fixture still calls
sqlite.Open.
No open or closed issue, and no open pull request, was found for this exact current slowdown after searches for build-test, slow CI, go test -race, SQLite fixtures, race detector SQLite, and migration package CI.
I dug into the slowdown and the issue’s diagnosis holds up. sqlitetest.Open creates a migrated template once, but each cloned DB still goes through sqlite.Open → migrate(), repeating the repair/probe work behind gooseMu.
this gets especially expensive under -race. The main fix looks like giving sqlitetest a path to open verified-current clones without re-running migrations, while keeping production sqlite.Open coverage intact for migration tests.
I’m looking into that path and the schema-version assertion needed to make it safe.
Assigned to @mohakchakraborty2004.
@Rishet11 , a PR #5162 already solves this , so ill be reviewing it , and mention you there if we can merge it or not
Addressed by #5162, #5632 and #6089 on main: migration tests reuse snapshots and run sharded. Reopen if CI time regresses.