Improve the performance of firo-qt on Mac when the UI is out of focus#1867
Improve the performance of firo-qt on Mac when the UI is out of focus#1867psolstice wants to merge 1 commit into
firo-qt on Mac when the UI is out of focus#1867Conversation
|
User peter@shugalev.com does not have a PR Review subscription. Go to Team management and add this email to the PR Review subscription. |
Summary by CodeRabbit
WalkthroughAdds a new ChangesApp Nap Inhibitor
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/qt/bitcoin.cpp (1)
759-764: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueEarly-return paths bypass
enableAppNap().Several
returnstatements betweendisableAppNap()(Line 763) andenableAppNap()(Lines 933-935) — e.g. Lines 806, 816, 822, 832, 839, 853, 879, 888 — exitmain()without re-enabling App Nap. Since the process terminates in all these cases, the OS reclaims the activity assertion regardless, so this is not currently harmful, but it breaks the disable/enable symmetry the class documents.A scope-guard (RAII) wrapper around
disableAppNap()/enableAppNap()would guarantee the pairing regardless of howmain()exits, and is more in line with using RAII instead of manual paired calls.Also applies to: 919-936
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/qt/bitcoin.cpp` around lines 759 - 764, The App Nap handling in main() is manually paired and several early return paths bypass the later enableAppNap() call, breaking the intended symmetry. Refactor the MacNapInhibitor usage in bitcoin.cpp around the existing disableAppNap() and enableAppNap() calls into a small RAII/scope-guard helper so App Nap is re-enabled automatically whenever main() exits, regardless of which return path is taken.Source: Coding guidelines
src/qt/macnapinhibitor.mm (1)
10-38: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueNo synchronization on shared activity-token state.
g_napActivityTokenis a plain global mutated by bothdisableAppNap()andenableAppNap(). Current call sites (main thread only, perbitcoin.cpp) don't race, but nothing in the header prevents future callers from invoking these from other threads, which would race on the check-then-act pattern (if (g_napActivityToken != nil) return;followed by assignment).Given the header guidelines call for
LOCK/TRY_LOCKmacros for multi-threaded state, consider guarding the token with a lock if this API is expected to be called from more than one thread.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/qt/macnapinhibitor.mm` around lines 10 - 38, The shared App Nap activity token is mutated without synchronization, so `MacNapInhibitor::disableAppNap()` and `MacNapInhibitor::enableAppNap()` should guard `g_napActivityToken` with a lock if there is any chance of multi-threaded use. Update the check-then-act logic in both methods to use the project’s locking pattern (`LOCK`/`TRY_LOCK`) around the token’s read/write/endActivity/release sequence, keeping the global state consistent even if future callers invoke these entry points off the main thread.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/qt/bitcoin.cpp`:
- Around line 759-764: The App Nap handling in main() is manually paired and
several early return paths bypass the later enableAppNap() call, breaking the
intended symmetry. Refactor the MacNapInhibitor usage in bitcoin.cpp around the
existing disableAppNap() and enableAppNap() calls into a small RAII/scope-guard
helper so App Nap is re-enabled automatically whenever main() exits, regardless
of which return path is taken.
In `@src/qt/macnapinhibitor.mm`:
- Around line 10-38: The shared App Nap activity token is mutated without
synchronization, so `MacNapInhibitor::disableAppNap()` and
`MacNapInhibitor::enableAppNap()` should guard `g_napActivityToken` with a lock
if there is any chance of multi-threaded use. Update the check-then-act logic in
both methods to use the project’s locking pattern (`LOCK`/`TRY_LOCK`) around the
token’s read/write/endActivity/release sequence, keeping the global state
consistent even if future callers invoke these entry points off the main thread.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8891303a-e4d8-4112-8ebc-59ba891d032a
📒 Files selected for processing (4)
src/qt/CMakeLists.txtsrc/qt/bitcoin.cppsrc/qt/macnapinhibitor.hsrc/qt/macnapinhibitor.mm
PR intention
When main window is out of focus on Mac the OS prioritises the performance of the application. This PR prevents that.
Code changes brief
Additional code in
src/qt/macnapinhibitor.h/ .mmprevents nap from happening