Skip to content

Commit 00b9da4

Browse files
authored
fix(perf): reduce idle CPU — gate audio sink, static shadow radius, cancel glow animation (#75)
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
1 parent 18f346e commit 00b9da4

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Sources/WhisKeyUI/FloatingHUDView.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ public final class FloatingHUDViewModel: ObservableObject {
3131
levelCancellable = publisher
3232
.receive(on: RunLoop.main)
3333
.sink { [weak self] level in
34+
guard let self, self.isRecording else { return }
3435
let boosted = Float(pow(Double(level), 0.4)) // expand low values
35-
self?.audioLevel = boosted
36-
self?.sampleBuffer.append(boosted)
37-
if (self?.sampleBuffer.count ?? 0) > 48 {
38-
self?.sampleBuffer.removeFirst()
39-
}
36+
self.audioLevel = boosted
37+
self.sampleBuffer.append(boosted)
38+
if self.sampleBuffer.count > 48 { self.sampleBuffer.removeFirst() }
4039
}
4140
}
4241

@@ -282,7 +281,7 @@ public struct WaveformHUDView: View {
282281
// Radius reduced to 3 for proportional bloom on the smaller 48×8 pt pill.
283282
.shadow(
284283
color: Color.white.opacity(viewModel.isRecording || reduceMotion ? 0.0 : (glowPhase ? 0.12 : 0.0)),
285-
radius: viewModel.isRecording || reduceMotion ? 1 : (glowPhase ? 3 : 1),
284+
radius: 2,
286285
x: 0,
287286
y: 0
288287
)
@@ -297,7 +296,7 @@ public struct WaveformHUDView: View {
297296
}
298297
.onChange(of: viewModel.isRecording) { isRecording in
299298
if isRecording {
300-
glowPhase = false
299+
withAnimation(.linear(duration: 0)) { glowPhase = false }
301300
} else if !reduceMotion {
302301
withAnimation(.easeInOut(duration: 3.2).repeatForever(autoreverses: true)) {
303302
glowPhase = true

0 commit comments

Comments
 (0)