Skip to content

fix(perf): reduce idle CPU — gate audio sink, static shadow radius, cancel glow animation - #75

Merged
rdemeritt merged 1 commit into
mainfrom
fix/idle-cpu-efficiency
Jun 4, 2026
Merged

fix(perf): reduce idle CPU — gate audio sink, static shadow radius, cancel glow animation#75
rdemeritt merged 1 commit into
mainfrom
fix/idle-cpu-efficiency

Conversation

@rdemeritt

Copy link
Copy Markdown
Member

Summary

  • Gate audioLevelPublisher sink on isRecording — stops 23–43 @Published updates/sec from AVAudioEngine tap firing while not recording
  • Make idle outer shadow radius static (2 pt) — animated radius forced per-frame CPU compositing at display refresh rate; only opacity continues to animate (CA-native)
  • Wrap glowPhase = false in withAnimation(.linear(duration: 0)) — explicitly cancels the running repeatForever CAAnimation on recording start, preventing animation accumulation across multiple record/stop cycles

Root cause

Three independent idle CPU leaks:

  1. AVAudioEngine tap fires ~23–43 Hz unconditionally; each tick wrote to two @Published properties (audioLevel, sampleBuffer), dirtying the SwiftUI view tree at tap rate even when idle
  2. SwiftUI .shadow(radius:) with an animated radius is not CA-native — compositor re-rendered the HUD layer at display refresh rate (60/120 Hz) for the entire app lifetime
  3. Setting glowPhase = false without withAnimation left orphaned repeatForever CAAnimations accumulating on the render server across record/stop cycles

Test plan

  • Activity Monitor: CPU usage visibly lower while WhisKey idle (not recording)
  • Glow border pulse still animates on the idle pill
  • Hotkey down → waveform and recording dot appear correctly
  • Hotkey release → waveform stops, pill collapses, glow resumes
  • Multiple record/stop cycles — no animation degradation over time
  • Reduce Motion: no regressions

…ancel glow animation

Three idle CPU fixes:
- Gate audioLevelPublisher sink on isRecording; stops 23–43 @published
  updates/sec from AVAudioEngine tap firing while not recording
- Make idle outer shadow radius static (2 pt); animated radius forces
  per-frame CPU compositing at display refresh rate — only opacity animates
- Wrap glowPhase=false in withAnimation(.linear(duration:0)) to explicitly
  cancel the running repeatForever CAAnimation on recording start, preventing
  animation accumulation across multiple record/stop cycles
@rdemeritt
rdemeritt merged commit 00b9da4 into main Jun 4, 2026
4 checks passed
@rdemeritt
rdemeritt deleted the fix/idle-cpu-efficiency branch June 4, 2026 11:19
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