Skip to content

perf(devbox): skip redundant runx, script and state-hash work per env compute - #3056

Open
mikeland73 wants to merge 2 commits into
mainfrom
claude/perf-shellenv-cleanups-18d199
Open

mikeland73 wants to merge 2 commits into
mainfrom
claude/perf-shellenv-cleanups-18d199

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Implements the env-compute / run bullets of item 17 ("Smaller cleanups") in specs/perf-improvements.md.

Changes

  • RunXPaths: fix(devbox): reconcile runx bin dir in place to avoid concurrent races #3019 already made it reconcile .devbox/virtenv/runx/bin in place, rewriting only changed links. It now also skips the filesystem entirely when there are no runx packages and no leftover links (most projects).
  • Scripts: writeScriptFileAtomic skips the write when the existing file already has the same contents and mode 0755, so devbox run no longer rewrites every script. It doesn't use overwriteFileIfChanged as the spec suggested: that writes in place, and another devbox process may be executing the script, which would bring back the races fixed in fix(devbox): make concurrent devbox run safe on shared script files #3032 and fix(shellgen): avoid ETXTBSY when forking while writing scripts #3037.
  • StateStatus memoization: it was computed twice per shellenv (ensureStateIsUpToDateAndComputeEnv, then ensureStateIsUpToDate). Each run hashes the lockfile, config, print-dev-env cache and nix profile. It's now cached on the Devbox only for the duration of one such call. The cache is dropped when the call returns, after the non-Nix refresh, and before any non-ensure mode (where the caller changed the config). The packages.go change is a few lines in ensureStateIsUpToDate, to stay clear of the concurrent Add/Remove/Update refactor.

Out of scope (other PRs): the FlakeUpdate removal and prefetch bullets of item 17, items 12–16.

Testing

  • New unit tests: TestRunXPathsWithoutRunXPackages, TestStateStatusCacheDoesNotOutliveCall, TestWriteScriptFileAtomicSkipsUnchanged
  • go test ./internal/devbox/... ./internal/shellgen/... ./internal/lock/... pass
  • go test -run TestScripts ./testscripts: all 67 pass, python_patch_cuda skipped

🤖 Generated with Claude Code

mikeland73 and others added 2 commits November 13, 2026 09:28
- RunXPaths: don't touch .devbox/virtenv/runx/bin when the project has no
  runx packages and no leftover links.
- Scripts: skip rewriting script files whose contents and mode already
  match. Keeps the temp-file + rename write (not overwriteFileIfChanged) so
  the concurrency/ETXTBSY fixes from #3032 and #3037 still hold.
- Memoize lockfile.StateStatus on the Devbox for the duration of one
  ensureStateIsUpToDate[AndComputeEnv] call instead of computing it twice
  per shellenv. The cache is dropped when the call returns, after the
  non-Nix refresh, and before any config-changing (non-ensure) mode.

Spec item 17 (smaller cleanups), env-compute/run bullets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest changes only correct documentation references.

Summary

This PR skips repeated work when computing the Devbox environment.

  • Projects without runx links skip creating an empty runx directory.
  • Unchanged scripts keep their files instead of being replaced.
  • Environment setup reuses its state check for the duration of a call.

Since the previous review, only the three PR references changed from placeholders to #3056. No new issues or repository-rule violations were found. No previous findings were supplied.

Reviews (2) · Last reviewed commit: "docs(spec): mark item 17 env-compute cle..." · Reviewed by Greptile

@mikeland73

Copy link
Copy Markdown
Collaborator Author

@greptileai review


Written by Claude on behalf of / prompted by @mikeland73.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant