You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a0b1cae
Browse filesBrowse the repository at this point in the historyBrowse files
perf(telemetry): reuse opened project, cache device ID, throttle uploads (#3021)
## Summary
Implements items 2–4 of `specs/perf-improvements.md`, which together
remove fixed telemetry costs from every command (including every `devbox
global shellenv` and every direnv reload).
**2. Don't re-open the project after every command**
- The telemetry post-run hook returns immediately when telemetry is
disabled (`DO_NOT_TRACK`, or builds without keys). Before, it still ran
`devbox.Open`.
- `devbox.Open` now records the project it returned
(`devbox.LastOpened()`), and telemetry reads packages and the nixpkgs
commit from that project instead of opening it again (which re-parsed
devbox.json/devbox.lock and reloaded plugins).
- That also gets rid of the `--config` bug: the old code looked the flag
up on the root command, so it never found it.
- Behavior change: commands that never open a project (e.g. `version`,
`search`) now report no packages. Before, they reported whatever project
was in the cwd.
**3. Cache the device ID**
- The salted `machineid.ProtectedID` is written to
`$XDG_STATE_HOME/devbox/telemetry/device-id` and read from there on
later runs. This skips `ioreg` on macOS (~20ms).
**4. Throttle `devbox upload-telemetry`**
- The uploader is spawned at most once every 30 minutes. In between,
events stay buffered on disk as they do today. It still runs right away
when an error was reported (so Sentry errors arrive promptly and the
Sentry transport's 30-event buffer isn't exceeded) or when 50+ events
are buffered.
- The last upload time goes in
`$XDG_STATE_HOME/devbox/telemetry/last-upload` before the child starts,
so commands running at the same time don't all spawn one. A timestamp in
the future is ignored.
- Sentry events now set `Timestamp` when they're created, since they may
be uploaded later.
## Testing
- `go test ./internal/telemetry/ ./internal/boxcli/midcobra/`: new tests
for the device ID cache (hit and miss) and `shouldUpload` (never
uploaded, recent, stale, future timestamp, error, threshold). Updated
the `getPackagesAndCommitHash` test.
- `golangci-lint run` on the changed packages: 0 issues.
- Timing on macOS, with binaries built with fake telemetry keys and
network blocked by a proxy, averaged over 20 runs in this repo:
| Command | main | this PR |
|---|---|---|
| `devbox version` | 106.6ms | 85.8ms |
| `devbox list` | 106.1ms | 86.3ms |
Most of the remaining cost is `nix --version` (~75ms), which
`newTrackMessage` calls through `nix.Version()`. Item 1 (a separate PR)
caches it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0 commit comments