Skip to content

Halve the server tests' time: keep their data in memory, and compile Argon2 optimized - #296

Merged
gccody merged 1 commit into
mainfrom
perf/server-tests-in-memory
Nov 20, 2026
Merged

gccody merged 1 commit into
mainfrom
perf/server-tests-in-memory

Conversation

@gccody

@gccody gccody commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

The server check spends about 7.5 minutes running tests. Almost none of that is the tests themselves.

Where the time went

Each test starts a server of its own, on SQLite and again on PostgreSQL, creates the first administrator, and tears it all down. Timing the steps of one simple test (tags_are_created_renamed_recolored_and_deleted, 1.85 s) on a real disk:

Step SQLite PostgreSQL
Write the instance key (synced) 67–89 ms 83 ms
Open the database 255 ms 3 ms
Migrate 100 ms 115 ms
First-run setup (one Argon2 hash) 380 ms 390 ms
Close (SQLite checkpoints and syncs) 245 ms <1 ms

With the temporary directory in memory, the key, open and close steps take under 4 ms together and the SQLite migration 29 ms. The Argon2 hash is slow only because test builds don't optimize it.

What changes

  • CI runs the server's tests with TMPDIR=/dev/shm, and keeps its PostgreSQL service's data on a tmpfs.
  • scripts/test-server-postgres.sh uses /dev/shm for its cluster and the tests' data where there is one, unless TMPDIR is set.
  • The dev profile compiles argon2 and blake2 at opt-level = 3. Only the server depends on them, so no other build changes.
  • docs/development.md says how to run the tests that way.

Nothing in the server or its tests changes.

Measured in CI

This PR's server job against #295's, both with a warm cache:

#295 (before) This PR
Running the tests 457 s 239 s
cargo test step (3 min 09 s of it is the build, both times) 10 min 49 s 7 min 11 s
Whole job 12 min 37 s 9 min 04 s

The PostgreSQL service started on its tmpfs and all 46 test binaries passed on both backends.

Measured locally

The whole suite in WSL, pinned to 4 cores as a CI runner has, SQLite and PostgreSQL (PostgreSQL with fsync=off in every run):

Test run Sum of every test's time
main 542 s 1,673 s
Argon2 optimized only 416 s 1,320 s
Argon2 optimized, data in memory 262 s 725 s

All 719 tests passed in the last run. sign_in went from 45 s to 4 s, and most binaries now take 2–5 s.

Left for later

realtime (48 s) and monitors (26 s) are now almost a third of the run: several realtime tests wait on the server's real two-second reading spacing and five-second ticks. The test build (3 min) and Clippy are untouched.

…Argon2 optimized

A server test starts a server of its own, on SQLite and again on PostgreSQL, creates the first administrator and tears it all down. Timing one simple test's steps showed that nearly all of its 1.85 s was that, not the test:

- The server syncs its key file, its SQLite database and the checkpoint at close to the disk: about 80 ms, 255 ms and 245 ms on a real disk, and under 4 ms together in memory.
- Argon2 runs unoptimized in test builds: about a third of a second for each password hashed.

So:

- CI runs the server's tests with TMPDIR=/dev/shm, and keeps its PostgreSQL service's data on a tmpfs.
- scripts/test-server-postgres.sh uses /dev/shm for its cluster and the tests' data where there is one, unless TMPDIR is set.
- The dev profile compiles argon2 and blake2 at opt-level 3. Only the server depends on them.
- docs/development.md says how to run the tests that way.

Nothing in the server or its tests changes.
@gccody
gccody merged commit 19a9780 into main Nov 20, 2026
9 checks passed
@gccody
gccody deleted the perf/server-tests-in-memory branch November 20, 2026 18:53
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