Repository navigation
perf: optimize CPU and WindowServer overhead during music playback - #40
Open
SnackForever wants to merge 5 commits into
Open
SnackForever wants to merge 5 commits into
SnackForever wants to merge 5 commits into
Conversation
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
…progress invalidation - EqualizerBar: replace GeometryReader dynamic frame height with native scaleEffect transform to eliminate 60/120Hz CPU layout recalculations in NSHostingView / WindowServer. - PlayerBar: extract PlayerBarProgressLaneContainer and PlayerBarMixTracksMenu to isolate playerService.progress observation; prevents re-evaluating Liquid Glass container, artwork glow shaders, and controls on every 500ms playback tick. - ObserverScript: cache hasVideo and throttle full-DOM querySelectorAll calls to eliminate recurring WebKit content process CPU load.
SnackForever
force-pushed
the
perf/reduce-cpu-equalizer-playerbar
branch
from
September 23, 2026 11:57
6d285c6 to
c30c366
Compare
…edback - fix(playerbar): wire PlayerBarSeekHold to mix segment seeks preventing stale observer progress jumps - fix(observer): prevent false-negative DOM query from overwriting authoritative hasVideo state - perf(lifecycle): introduce WindowOcclusionMonitor to suspend continuous GPU/CPU animations when window is on inactive Spaces or occluded (-95% background CPU) - perf(equalizer): keep full 120Hz ProMotion fluidity while eliminating background render load
Author
Note on CI Checks StatusFor visibility during review, the failing checks reported by CI are pre-existing issues present on
|
Owner
|
Hi @SnackForever thanks for the PR. I will take a look in these weeks, I'm quite busy |
Author
No problem, have a nice day |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
This PR optimizes CPU, GPU, and
WindowServerutilization during music playback on macOS (especially on Apple Silicon with multi-monitor / 120Hz ProMotion displays).Profiling identified that:
EqualizerViewtriggered repetitive AppKit view layout passes (NSView layoutSubtreeIfNeeded).PlayerBarre-evaluated the artwork glow, Liquid Glass styling, and controls on every progress tick.PlayerBarMarqueeTextcaused repeated CoreText glyph rasterization on each frame.SingletonPlayerWebViewcaused unnecessary WebKit IPC overhead.Key Highlights
NSWindow.occlusionStatetracking.hasVideoresult caching.layoutIfNeeded), offloading bar scaling and text scrolling to CoreAnimation / Metal while keeping 100% of 120Hz ProMotion fluidity intact.hasVideoDOM fallback protection).Type of Change
Changes Made
1. Window Occlusion & Background Lifecycle (
WindowOcclusionMonitor.swift,AppDelegate.swift)WindowOcclusionMonitortrackingNSWindow.occlusionStateviawindowDidChangeOcclusionState.Cmd + W, continuous GPU/CPU animation loops immediately suspend.2. Equalizer Bar GPU Scale Transforms (
EqualizerView.swift).frame(height:)height recalculations with.scaleEffect(y: self.heightFraction, anchor: .bottom).NSView layoutSubtreeIfNeeded), offloading bar scaling to GPU CoreAnimation / Metal.3. State Invalidation Isolation & Seek Hold Fix (
PlayerBar.swift)PlayerBarProgressLaneContainerandPlayerBarMixTracksMenu).PlayerBarSeekHoldtoPlayerBarMixTracksMenusegment seeks to eliminate stale observer progress bounce-back.4. GPU Texture Compositing (
PlayerBarMarqueeText.swift).compositingGroup()modifier to the scrolling textHStackso Core Animation renders glyphs into a single GPU texture layer rather than re-rasterizing text glyphs via CPU CoreText (TRun::DrawGlyphs) on each display frame.5. WebKit DOM Query Throttling & Caching (
SingletonPlayerWebView+ObserverScript.swift)MutationObserverdebounce and cachedhasVideoelement query results.Empirical Benchmark
Measured on macOS Tahoe (Apple Silicon, 120Hz ProMotion display) using the track Enemy (Arcane) across different real-world usage scenarios:
42.4% WindowServer
25.9% – 26.7% WindowServer
~50% WS reduction
47.5% WindowServer
33.0% – 44.0% WindowServer
Cmd + W)~36.5% WindowServer
~26.0% WindowServer
258 layout passes
144 layout passes
100% fluid ProMotion
Testing
swift test --filter PlayerBarandswift test --filter Equalizerpass cleanly)Checklist
swiftlint --strict && swiftformat .CodeAnt-AI Description
Reduce CPU and rendering work during music playback while keeping progress and segment seeking accurate
What Changed
Impact
✅ Lower CPU while music plays in hidden or covered windows✅ Smoother equalizer and marquee playback visuals✅ Fewer progress-related player bar refreshes✅ Reliable segment seeking without progress jumps💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.