Skip to content

0037: Cheaper git open, and a test-only Argon2id memo

  • Status: accepted
  • Date: 2026-10-08
  • Amends: 0019 (how often git version runs, and how the work tree is located)

Context

Two performance problems, found by profiling.

  1. gitstore.Open started two git processes on every command: git version (the 2.30 minimum) and git rev-parse --show-toplevel --show-prefix. That was about 95% of a warm vaultfold run, 16 ms natively and 160 to 270 ms on a Windows ARM VM (agentboard ticket 01M4C7WA60TM2TT0NG49CRFFVZ).
  2. The cmd/vaultfold/internal/cli tests took 10 minutes under -race on an idle machine and 17 to 32 minutes under load (agentboard ticket 01M4DSWBJAEFFY55E5MEFQHQFY). About 80% of the CPU was Argon2id: every command in a test unlocks the same fixture key file, which costs one 64 MiB, 3 pass, 4 lane derivation each time, and -race makes that several times slower. A second cost was agent start, agent unlock and agent-mode on in the JSON audit starting the test binary as a daemon without the variable that makes it one; Go's flag parsing stops at agent, so the child re-ran the whole suite until the 5 second start timeout killed it.

Decision

  • The git version check is remembered in <runtime>/git-version (gitstore.Options.VersionCache), keyed by the resolved git executable's path, size and modification time. Only a passing check is written, so a failed check is never cached and a replaced executable is checked again. A missing, corrupt or unwritable file just means the check runs. Known limit: a wrapper or shim whose own size and mtime stay fixed while the git behind it changes (xcode-select on macOS, asdf, mise, scoop shims) keeps its cached pass until the file is deleted; gitstore.Open with no options still checks on every call.
  • The work tree is found without starting git only when the nearest ancestor .git is a plain directory shaped like a git directory (HEAD, objects/, refs/) and owned by the current user (unix), no directory on the way up is itself a git directory, the config has no core.worktree, no bare key other than false, no include and no extensions, none of GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR, GIT_CEILING_DIRECTORIES, GIT_DISCOVERY_ACROSS_FILESYSTEM, GIT_NAMESPACE or GIT_OBJECT_DIRECTORY is set, and every element of the path is spelled as on disk (checked by directory listing only where the filesystem is case-insensitive, because git prints the on-disk case and the prefix is matched against git output). Everything else (a .git file of a linked work tree or submodule, a bare repository, no repository, a vault inside .git) still asks git rev-parse. DECISION: two differences are accepted. Git stops at a filesystem boundary and the walk does not, so a vault on another mount than its repository opens where git alone would report "not a git repository". On Windows the owner is not read, so git's safe.directory refusal for a repository owned by someone else appears at the first git command instead of in Open.
  • Under the build tag vaultfold_testkdf, and only in a test binary (testing.Testing()), suite.Argon2idKeyUnchecked memoizes its result per (passphrase, salt, parameters). It lowers no cost parameter, still runs the real derivation for every distinct input, and returns a fresh copy to each caller. scripts/coverage.sh passes the tag to the cmd/vaultfold module only; core/suite and core/identity run the real function on every call, and a test pins that an untagged build has no memo. No release or Makefile build passes the tag.
  • The cli test binary exits at once when started as <exe> agent ... without VAULTFOLD_TEST_CLI_MAIN=1.

Consequences

  • A warm command spawns no git when the layout is plain and the version is cached, so TestRunStartupBudget runs on Windows again.
  • Tests do not run in parallel: session.CloseAll, which the commands and the test cleanups call, is process-wide and would zero another test's unlocked keys. Parallelism needs a per-profile registry first.