Skip to content

Commit 676f663

Browse files
Vincent Herbstclaude
andcommitted
fix(nowplaying): decode the cover once, not once a second
`update` runs on the throttled Now-Playing tick, about once a second for the whole session, and decoded `metadata.artworkData` on every one of them. The bytes never change during a file, so that is a full image decode per second for a constant result, and MediaPlayer re-encodes the bitmap on top. On a file with a poster-sized embedded cover it dominated the process. Measured on the same A/V with and without one, 25 s window each: cover, before 18.8% of a core PNG = 60.5% of all running samples no cover 5.8% of a core PNG = 0% cover, after 6.0% of a core PNG = 0% That is the shape reported in AetherPlayer#2: the reporter sees 17-25% for an mp4 with cover art against about 4% for the engine's own demo on the identical file, and about 4% for a MKV remux of it, which does not carry the cover in a form the engine surfaces. The engine was never involved. Keep the decoded artwork and rebuild it only when the bytes change, which is the gate `NowPlayingView` already applies to its own copy. Cleared on stop so a following file cannot inherit the previous cover. 68 tests pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
1 parent f20c2f0 commit 676f663

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎Sources/Shared/NowPlaying/NowPlayingController.swift‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ final class NowPlayingController {
1515
private let commands = MPRemoteCommandCenter.shared()
1616
private var configured = false
1717

18+
/// Decoded cover, kept across pushes and rebuilt only when the bytes change.
19+
/// `update` runs on the throttled clock tick (about once a second for the
20+
/// whole session), and decoding the embedded artwork there re-ran a full
21+
/// image decode every second for artwork that never changes. On a file with
22+
/// a poster-sized cover that dominated the process: measured 18.8% of a core
23+
/// against 5.8% for the same A/V without one, with PNG decoding 60% of all
24+
/// running samples (AetherPlayer#2). `NowPlayingView` already gates its own
25+
/// copy on the artwork bytes; this is the same gate on the system surface.
26+
private var artworkSource: Data?
27+
private var artwork: MPMediaItemArtwork?
28+
1829
/// Wire transport commands once. Each closure calls back into the
1930
/// supplied action set (the view model's methods).
2031
func configure(actions: Actions) {
@@ -52,8 +63,15 @@ final class NowPlayingController {
5263
var dict = nowPlayingInfo(
5364
metadata: metadata, fallbackTitle: fallbackTitle,
5465
duration: duration, elapsed: elapsed, rate: rate)
55-
if let data = metadata?.artworkData, let image = NSImage(data: data) {
56-
dict[MPMediaItemPropertyArtwork] = Self.makeArtwork(image)
66+
if let data = metadata?.artworkData {
67+
if artworkSource != data {
68+
artworkSource = data
69+
artwork = NSImage(data: data).map { Self.makeArtwork($0) }
70+
}
71+
if let artwork { dict[MPMediaItemPropertyArtwork] = artwork }
72+
} else if artworkSource != nil {
73+
artworkSource = nil
74+
artwork = nil
5775
}
5876
info.nowPlayingInfo = dict
5977
info.playbackState = rate > 0 ? .playing : .paused
@@ -72,6 +90,8 @@ final class NowPlayingController {
7290
func clear() {
7391
info.nowPlayingInfo = nil
7492
info.playbackState = .stopped
93+
artworkSource = nil
94+
artwork = nil
7595
}
7696

7797
struct Actions {

0 commit comments

Comments
 (0)