Skip to content

menubar: 30s refresh spawns concurrent Node CLI processes at 100%+ CPU with App Nap disabled (video-call-class energy drain) #647

Closed

Description

@iamtoruk

Report

User report: the menubar app's energy use on macOS rivals a browser video call. Confirmed by measurement on an M-series MacBook running 0.9.15.

Measured evidence

Sampling the process table at 0.4s intervals for 60s while the menubar idled (popover closed):

  • One refresh tick spawned TWO concurrent full Node processes: codeburn status --format menubar-json --provider all --period today --no-optimize and the same for --period week.
  • Each was observed at 102-121% CPU for roughly 1-3 seconds (V8 cold start, pricing load, cache read, session parse).
  • At the 30s cadence that is ~120 Node cold starts per hour, or two-plus full-core seconds burned every 30 seconds, forever.
  • The app holds a permanent activity assertion (mac/Sources/CodeBurnMenubar/CodeBurnApp.swift:84, beginActivity with automaticTerminationDisabled at launch, never scoped to a fetch), so App Nap never throttles this, including on battery.
  • Combined-device mode issues a third fetch per tick (mac/Sources/CodeBurnMenubar/AppStore.swift:459-471).

Activity Monitor attributes child processes to the responsible app, so the menubar's Energy Impact reads in the video-call class. Machines with large session histories or cold caches (first run, Cursor sqlite) see much longer spikes, and the missing cross-process cache lock (#645) makes concurrent CLI/MCP/menubar runs re-parse repeatedly.

Proposed fix ladder (cheapest first)

  1. Change-detection guard: before spawning, stat the known provider data roots; skip the fetch entirely when nothing changed since the last one. Most 30s ticks are no-ops on an idle machine.
  2. Refresh the popover period (week etc.) only while the popover is open; the closed menubar only needs the status period.
  3. Adaptive cadence: 30s only while the popover is open or on AC power; back off to 2-5 min on battery, Low Power Mode, or display sleep.
  4. Set qualityOfService = .utility on the spawned Process so spikes prefer efficiency cores.
  5. Scope the activity assertion to in-flight fetches instead of holding it for the app's lifetime.
  6. Longer term: a resident helper process (same reasoning as the MCP server's resident design) to eliminate the per-tick Node cold start.

Items 1-5 are Swift-side and shippable without touching the CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions