Repository navigation
perf(nix): cache nix version info on disk - #3020
Merged
Merged
Conversation
Every devbox command runs `nix --version --debug` (~90ms) to get the Nix version and system, and the result was only cached per process. Persist the parsed Info under the XDG cache dir so later commands can skip it. The cache key is the resolved nix binary path, the command arguments, and the environment variables that affect Nix's config. The entry also stamps (mtime + size) the nix binary and every nix.conf that --debug reports, including ones that don't exist yet, so editing or creating a config invalidates it. Entries expire after 24h as a backstop for changes the stamps can't see (e.g. nix.conf include directives). Failures aren't cached. Also skip the nix.System() lookup in IsEnabledOnPlatform when a package doesn't restrict its platforms. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
@claude ptal |
|
Claude finished @mikeland73's task in 20s —— View job Review of #3020: cache nix version info on diskI read the diff and the surrounding What looks good
Minor points and nits
Approving from my side, with the |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements item 1 of
specs/perf-improvements.md.Every devbox command calls
nix.Info()(viaEnsureNixInstalled,nix.System(), telemetry, etc.), which runsnix --version --debug(~90ms). The result was only cached per process. This persists the parsedInfounder$XDG_CACHE_HOME/devbox/nix-info/using the existingfilecachehelper.Cache key: resolved nix binary path (symlinks followed, usually an immutable
/nix/store/...path) + command args (incl.ExtraArgs) + env vars that affect Nix's config (NIX_CONF_DIR,NIX_CONFIG,NIX_USER_CONF_FILES,XDG_CONFIG_HOME,XDG_CONFIG_DIRS,HOME,NIX_STORE_DIR, ...).Invalidation: each entry stamps (mtime + size) the nix binary and every config file
--debugreports — the systemnix.confand every user config path, including ones that don't exist yet, so creating one invalidates too. Entries also expire after 24h as a backstop for changes the stamps can't see (e.g. files pulled in byincludeinnix.conf). Failures are never cached, and the in-processinfoOnceis unchanged.Also:
Package.IsEnabledOnPlatformnow returnstrueearly when a package sets neitherplatformsnorexcluded_platforms, so the common case never looks upnix.System().Timing
devbox global shellenvwith the project already up to date,DO_NOT_TRACK=1, 15 runs each:Apart from the debug timer lines, the output matched main exactly.
Testing
nix/infocache_test.gouses a fake nix script and checks: a cache hit skips nix, editingnix.confinvalidates, creating a previously missing user config invalidates, changingNIX_CONFIGchanges the key, and failures aren't cached.go test -race ./nix/... ./internal/nix/... ./internal/devconfig/...passgolangci-lintreports 0 issues andgofumpt -extrais clean🤖 Generated with Claude Code