0037: Cheaper git open, and a test-only Argon2id memo
- Status: accepted
- Date: 2026-10-08
- Amends: 0019 (how often
git versionruns, and how the work tree is located)
Context
Two performance problems, found by profiling.
gitstore.Openstarted two git processes on every command:git version(the 2.30 minimum) andgit rev-parse --show-toplevel --show-prefix. That was about 95% of a warmvaultfold run, 16 ms natively and 160 to 270 ms on a Windows ARM VM (agentboard ticket 01M4C7WA60TM2TT0NG49CRFFVZ).- The
cmd/vaultfold/internal/clitests took 10 minutes under-raceon 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-racemakes that several times slower. A second cost wasagent start,agent unlockandagent-mode onin the JSON audit starting the test binary as a daemon without the variable that makes it one; Go's flag parsing stops atagent, 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.Openwith no options still checks on every call. - The work tree is found without starting git only when the nearest
ancestor
.gitis 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 nocore.worktree, nobarekey other than false, no include and no extensions, none ofGIT_DIR,GIT_WORK_TREE,GIT_COMMON_DIR,GIT_CEILING_DIRECTORIES,GIT_DISCOVERY_ACROSS_FILESYSTEM,GIT_NAMESPACEorGIT_OBJECT_DIRECTORYis 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.gitfile of a linked work tree or submodule, a bare repository, no repository, a vault inside.git) still asksgit 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.Argon2idKeyUncheckedmemoizes 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.shpasses the tag to thecmd/vaultfoldmodule only;core/suiteandcore/identityrun 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 ...withoutVAULTFOLD_TEST_CLI_MAIN=1.
Consequences
- A warm command spawns no git when the layout is plain and the version
is cached, so
TestRunStartupBudgetruns 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.