Skip to content

perf(memory): read macOS footprints with a bundled helper instead of top - #34053

Merged
OrcaWin merged 1 commit into
mainfrom
ram/footprint-helper
Oct 26, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
ram/footprint-helper

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​50
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​213 $\color{#cf222e}{\Huge{\mathbf{−}}}$​103 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110

Summary

Follow-up to #33901. The memory panel's macOS footprint now comes from a small bundled Swift helper (orca-process-footprint) that calls proc_pid_rusage for every same-user process. Previously it came from /usr/bin/top.

top does a system-wide sample that costs about a quarter-second of CPU no matter which PIDs are asked for, so #33901 had to cache it for 10 s. The helper is about 90× cheaper per sample. Memory figures now refresh on the panel's normal 2 s poll, and the panel uses about 18× less CPU overall.

Data (M4 Air, ~460 same-user processes, ~770 total)

Per sample, 50 helper runs and 10 top runs, child CPU taken from getrusage(RUSAGE_CHILDREN):

CPU per sample Wall per sample Cadence CPU while panel is open
top -l 1 -stats pid,mem (before) 263 ms 265 ms 10 s ~26 ms/s
orca-process-footprint (after) 2.9 ms 3.9 ms 2 s ~1.5 ms/s
  • Filtering top to our own PIDs (-pid …), or adding -F, -R or -n 0, made no difference; its cost is fixed.
  • Electron's app.getAppMetrics() reports RSS on macOS, not footprint, so it can't replace this.
  • The helper's numbers match top (for example 454070088 B vs top's 433M for the same PID), and it still works when signed with the hardened runtime.

How it ships

The helper follows the orca-keyboard-layout pattern:

  • Build: single-file Swift, built universal by build:process-footprint-macos. That script runs from build:native (which the release, daily and hourly macOS workflows use) and from build:mac / build:mac:release.
  • Packaging and signing: extraFiles puts it at Contents/MacOS/orca-process-footprint, and afterPack signs it with signMacStandaloneHelper. A release build without it fails, just like the keyboard helper.
  • Dev: dev bundles build it for the host architecture. It is also on the dev bundle's required-resource list, so existing dev bundle copies rebuild once.
  • Shared build code: the keyboard-layout build script and the dev-runner helper builds now share swift-cli-helper-macos.mjs. The output is the same as before; this also keeps the dev runner under its line limit.

Fallbacks

  • Helper missing: use top with the existing 10 s cache.
  • Helper fails before ever succeeding (for example quarantine or wrong architecture): switch to top permanently.
  • Helper fails after a good sample: keep the last good sample, the same rule top already followed.
  • top also unavailable: RSS, unchanged from before.
  • Linux and Windows are untouched.

Merge risk

Low to medium. The runtime change is small and every failure path falls back to today's behavior. The risk is in packaging: a new signed binary goes into Contents/MacOS, so the first release or notarization run with it is the real check. If signing is wrong, the release fails loudly instead of shipping silently.

User-facing trade-offs

None. Memory figures are fresher (2 s instead of up to 10 s old) and the panel uses less CPU.

Tests

  • collector-darwin-footprint.test.ts: the helper is preferred and top is not run when the helper is present; a failing helper falls back to top. The existing top and RSS cases are kept.
  • build-native-for-platform.test.mjs: now expects four parallel macOS native builds.
  • pnpm check:changed passes with all 36 checks.

…lper instead of top

top costs ~263 ms of CPU per sample, so the memory panel only refreshed
footprints every 10 s. The new orca-process-footprint helper reads
phys_footprint for every same-user process in ~3 ms, so footprints now
refresh on the panel's 2 s poll. top stays as the fallback when the helper
is missing or fails.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds a macOS utility that reports process physical-footprint values. Build scripts compile the utility, and macOS packaging includes and signs it. The Darwin collector uses the helper when available and falls back to /usr/bin/top when helper sampling fails. The development runner builds both Swift helpers and checks that both are present in a cached app bundle. Tests cover build-process counts and helper selection and fallback.

Priority: Low

Merge Risk: Low · up to 1a2e2

Repeated helper failures can leave process memory readings stale until restart. This is a bounded merge risk that warrants owner follow-up.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 10 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: macOS memory footprints are now read by a bundled helper instead of top. It also uses the conventional perf(memory) prefix. The title is specific and matches the o…
Description check Passed The description follows the repository template closely. It has a Summary, benchmark data, packaging and build notes, fallback behavior, merge risk, user-facing trade-offs, and test notes. It omits th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: macOS memory footprints are now read by a bundled helper instead of top. It also uses the conventional perf(memory) prefix. The title is specific and matches the objectives and the file summaries.

Full details: Description check

Explanation

The description follows the repository template closely. It has a Summary, benchmark data, packaging and build notes, fallback behavior, merge risk, user-facing trade-offs, and test notes. It omits the template's ELI5, What Changed, and Why headings as labeled sections, and the Linked Issue section is blank (Fixes # has no number). The Visual Proof section is missing, and no Testing checkboxes are ticked. The AI Disclosure section and the Agent skill upstream boundary checkbox are also absent. Most required information is present, so the description is mostly complete.

Resolution

Consider these additions before merge: (1) add an ELI5 section and label the Summary as What Changed and Why, or map its content onto those headings; (2) add the linked issue number in Fixes # (the template requires one for outside contributors); (3) state that Visual Proof is N/A with a reason, since the change affects memory panel refresh behavior and CPU use, not layout; (4) tick the Testing checkboxes that apply; (5) complete the Agent skill upstream boundary checkbox; (6) confirm the Checklist items, such as lint, typecheck, and build.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 10 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
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: 0edb372a-80ea-4011-9dca-be9a27e0059f
Commits

Reviewing files that changed from the base of the PR and between fa3bd28 and 1a2e2bd.

Files selected for processing: 11
  • config/electron-builder.config.cjs
  • config/scripts/build-keyboard-layout-macos.mjs
  • config/scripts/build-native-for-platform.mjs
  • config/scripts/build-native-for-platform.test.mjs
  • config/scripts/build-process-footprint-macos.mjs
  • config/scripts/run-electron-vite-dev.mjs
  • config/scripts/swift-cli-helper-macos.mjs
  • native/process-footprint-macos/main.swift
  • package.json
  • src/main/memory/collector-darwin-footprint.test.ts
  • src/main/memory/darwin-process-footprint.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +106 to +107
if (cache) {
return cache.footprints

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Fall back after repeated helper failures.

If the helper succeeds once and then fails on every sample, this branch returns the same cached footprints forever. The helper remains selected, so the collector never tries top and the memory reading stops updating. Keep the cached sample for a transient failure, but switch to top after repeated failures or a bounded stale period.

@OrcaWin
OrcaWin merged commit d58ab97 into main Oct 26, 2026
89 of 91 checks passed
audichuang added a commit to audichuang/orca that referenced this pull request Oct 29, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Oct 30, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 2, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 3, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 4, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 5, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 5, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 6, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 7, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 8, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 8, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 10, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 10, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 12, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 13, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 14, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 16, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 18, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 18, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 19, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
audichuang added a commit to audichuang/orca that referenced this pull request Nov 21, 2026
上游 v1.4.243(stablyai#34053)新增 macOS helper orca-process-footprint,fork 的 Makefile
computer-use target 沒建它;ad-hoc 的 PR 建置缺 helper 不會紅,只有 Developer ID
正式建置會丟錯,v1.4.243-fork.1 因此發版失敗。新增 fork-mac-helpers.mjs(進
fork-check-lint):上游 build:mac:release 跑的每個 build:*-macos,computer-use
target 都要有,下次上游再加 helper 會在本機閘門與 PR CI 就紅。
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.

1 participant