Skip to content

perf(stats): stop retaining and rewriting the raw stats event log - #35852

Merged
nwparker merged 2 commits into
mainfrom
perf/events-collector-35544
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
perf/events-collector-35544

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5

ELI5

Orca's usage stats file kept a log of up to 10,000 raw events and rewrote all of it, about 2 MB, every 5 seconds while agents were active. Nothing ever reads that log; only the running totals are used. The collector now keeps just the totals.

What Changed

  • src/main/stats/collector.ts:
    • The in-memory event array and its MAX_EVENTS = 10_000 cap are gone; record() only updates aggregates.
    • Saves still write events: [], so the file keeps schema v1 and older builds parse it unchanged.
    • Loading an older file that still has events schedules one batched save, so the file shrinks without waiting for agent activity.
  • src/main/stats/types.ts: comments updated.
  • collector-async-save.test.ts: replaces the old "bounds retained events" test (fix(stats): bound retained events during stalled writes #20941). The new test checks that an old event-heavy file is compacted and that new activity keeps the file under 1 KB with correct totals.

Why

Benchmark: 10K realistic events, 40 panes, 8 worktrees, 50 PRs.

before after
Stats file size 2,025,790 B 2,466 B
Main-thread JSON.stringify per save 5.03 ms 0.002 ms
Boot parse 8.2 ms 0.04 ms
Worst-case disk writes per active hour 1.46 GB 1.8 MB

Where this came from

Linked Issue

Fixes #35544

Visual Proof

N/A: no UI change. The stats summary shown in the app is computed from the same aggregates.

Testing

  • pnpm test src/main/stats src/main/quit-path-durable-write-blocking.test.ts: all pass.

  • pnpm check:changed --maxWorkers=2: 21/21 checks pass.

  • Adversarial reviews by Opus and Codex (gpt-6.1-sol, xhigh), both MERGE. Both searched the whole repo and found no reader of raw stats events in diagnostics, mobile, CLI, telemetry, star-nag or RPC. Both also verified that aggregates are preserved exactly from old files and that old/new builds can share the file without double counting.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Risk

Existing raw event history in users' stats files is dropped on first save. It was never surfaced anywhere. Aggregates (totals, counted PRs, firstEventAt) are unchanged.

🤖 Generated with Claude Code

…5544)

The collector kept up to 10K raw events (~203 B each since #14657 switched
meta to pane keys and added worktree ids) and re-serialized the whole ~2 MB
file every 5 s. No consumer reads events; persist aggregates only, keep the
v1 file shape with an empty events array, and compact legacy files on load.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a17ff924-7f19-46e0-bd75-05ba85642ab2
Commits

Reviewing files that changed from the base of the PR and between be80a9a and dec1022.

Files selected for processing: 3
  • src/main/stats/collector-async-save.test.ts
  • src/main/stats/collector.ts
  • src/main/stats/types.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The collector stops retaining raw events and saves only running totals, while keeping events: [] for file compatibility.

  • Stats saves keep totals without retaining the raw event log.

Reviews (1) · Last reviewed commit: "test(stats): use a small event burst for..." · Reviewed by Greptile

@nwparker
nwparker merged commit a41fec9 into main Oct 29, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Other]: (perf) Events collector stores much more info then initially designed.

1 participant