Skip to content

perf(status-bar): guard usage-notice anchor against equal-geometry re-render churn - #9615

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/status-bar-notice-churn-guard
Jul 20, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/status-bar-notice-churn-guard

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

What & why

The status-bar "Usage now shows % used" callout (UsagePercentageDisplayChangeNotice) positions a position: fixed card above the usage meters. It re-measures its anchor on every ResizeObserver / window-resize delivery and calls setAnchorPosition(measureAnchorPosition(anchor)) — a new object every time. Because the object identity changes, React re-rendered on every delivery even when the geometry was identical (the common case: meters reflow, agent-status ticks, background repaints).

This PR guards setAnchorPosition with a functional updater that returns the previous reference when bottom/left are unchanged, so React short-circuits before commit.

⚠️ Scope honesty: this is defensive robustness/perf hardening, not a proven crash fix. It surfaced while investigating crash f75ed81b (React #185 "Maximum update depth exceeded" in overlay.status-bar, still occurring after the react/radix bump in #8679). We reproduced enough to prove the notice component is not the root cause — the actual #185 loop lives inside radix Popper's layout effect and does not reproduce under unit/happy-dom. This PR removes one re-render-churn source feeding that subtree; it does not claim to close f75ed81b.

CLEAR, undeniable fix evidence

Unit test counts commits (React Profiler.onRender) across 20 identical-geometry ResizeObserver deliveries:

extra commits over 20 deliveries
Without the guard 20 (one re-render per delivery)
With the guard 1 (single post-open settling commit; deliveries 2–20 all bail)
  • Reverting only the source guard makes the new test fail (expected 20 to be less than or equal to 1); with the guard it passes. Verified independently by a second reviewer via git stash.
  • Full file suite: 9/9 passing. oxlint + oxfmt clean (pre-commit).
$ npx vitest run --config config/vitest.config.ts .../UsagePercentageDisplayChangeNotice.test.tsx
 Test Files  1 passed (1)
      Tests  9 passed (9)

ELI5

A little pop-up above your usage bars asks the window "where are you?" many times a second so it can float in the right spot. Every time it asked, it wrote down a brand-new sticky note with the answer — and React treats a new sticky note as "something changed!" and repaints, even when the answer was the exact same spot. Now the pop-up checks first: "same spot as last time? then keep the old sticky note" — so React stops repainting for no reason. 20 needless repaints → 1.

Trade-offs / regressions

  • None user-facing. Pure referential-equality optimization. When geometry genuinely changes, the returned value is identical to the old code path, so the card still repositions on window resize, status-bar compact toggle, and anchor moves (verified: bottom folds window.innerHeight, left folds window.innerWidth; any real move changes one and returns the fresh value). Initial placement is unchanged (prev is null → returns the new value).
  • Tiny per-delivery closure allocation, which buys an avoided re-render — net win. Perf review confirmed useLayoutEffect is the correct home (fixed positioning must measure synchronously pre-paint; rAF would flicker).

Adversarial review + perf

  • Adversarial review loop: 2 loops → CLEAN. Each loop a fresh sub-agent.
    • Loop 1 returned "CLEAN" but asserted the guard yields "exactly 0" extra commits. Empirically that was wrong (it's exactly 1). Caught it, corrected the test assertion to the honest ≤1 bound and the comment to "measured 20 → measured 1".
    • Loop 2 independently verified via git stash (20 without / 1 with), confirmed no stale-position risk (compared fields are an exact superset of render inputs), no leftover debug code, AGENTS.md-compliant → CLEAN.
  • Perf review (/perf skill, sub-agent): PASS. Smallest behavior-preserving fix; correct measurement (Profiler commit count); no remaining waste worth acting on; no new perf risk.

…-render churn

The UsagePercentageDisplayChangeNotice callout re-measures its fixed anchor
on every ResizeObserver/resize delivery and calls setAnchorPosition with a
fresh object each time. Equal-geometry deliveries (the common case) still
churned a re-render apiece because the object identity changed.

Bail when bottom/left are unchanged so React short-circuits before commit.
Measured: 20 identical-geometry deliveries → 20 re-renders before, 1 after.

This is defensive robustness/perf hardening for the status-bar subtree that
surfaced in crash f75ed81b (React #185 in overlay.status-bar). It is NOT a
proven fix for that crash — the reproduced #185 loop lives in radix Popper
internals and is not unit-reproducible; this removes one churn source feeding
that subtree.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 683d1c05-9cd5-4e54-a2a3-4cc2f9ffe838

📥 Commits

Reviewing files that changed from the base of the PR and between e109e78 and c2b2685.

📒 Files selected for processing (2)
  • src/renderer/src/components/status-bar/UsagePercentageDisplayChangeNotice.test.tsx
  • src/renderer/src/components/status-bar/UsagePercentageDisplayChangeNotice.tsx

📝 Walkthrough

Walkthrough

UsagePercentageDisplayChangeNotice now compares measured anchor coordinates before updating positioning state. The test environment adds a controllable ResizeObserver stub, and a Profiler-based test repeatedly delivers unchanged resize notifications after opening the notice to verify that render commits remain limited.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it does not follow the required template sections for screenshots, testing, AI review, security audit, or notes. Add the missing template sections, especially screenshots/no visual change, testing checklist, AI review with cross-platform confirmation, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: preventing equal-geometry re-render churn in the status-bar usage notice.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@brennanb2025
brennanb2025 merged commit 5829344 into main Jul 20, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…-render churn (stablyai#9615)

The UsagePercentageDisplayChangeNotice callout re-measures its fixed anchor
on every ResizeObserver/resize delivery and calls setAnchorPosition with a
fresh object each time. Equal-geometry deliveries (the common case) still
churned a re-render apiece because the object identity changed.

Bail when bottom/left are unchanged so React short-circuits before commit.
Measured: 20 identical-geometry deliveries → 20 re-renders before, 1 after.

This is defensive robustness/perf hardening for the status-bar subtree that
surfaced in crash f75ed81b (React stablyai#185 in overlay.status-bar). It is NOT a
proven fix for that crash — the reproduced stablyai#185 loop lives in radix Popper
internals and is not unit-reproducible; this removes one churn source feeding
that subtree.
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