Repository navigation
Open and close the lyrics within 50 ms - #715
Conversation
isaaclins
left a comment
There was a problem hiding this comment.
I ran it on my Mac mini (Release, scripts/latency-test.sh --only lyrics.toggle, load average around 4-5, so a fairly quiet Mac). Closing is well inside the budget, opening isn't yet, so lyrics.toggle still fails the gate:
| run | median | checked | opening | closing |
|---|---|---|---|---|
| 1 | 53.5 ms | 68.2 ms | 64-70 ms | 37-43 ms |
| 2 | 48.7 ms | 52.8 ms | 51-72 ms | 34-47 ms |
The 37-40 ms estimate for a quiet Mac holds for closing but not for opening. Everything else checks out: make build, make test (2559 tests, 0 failures) and the periphery scan (only SpotiglassSettingsView.columnVisibility, as on main).
|
|
||
| var body: some View { | ||
| ZStack { | ||
| if isShowing { |
There was a problem hiding this comment.
Opening still builds the lyrics from nothing on every ⌥⌘L. In a Time Profiler trace of 40 opens, the first frame of an open is almost all NSHostingView.layout() building this view: the lazy stack of lines, their text, the focus modifiers and the AppKit views inside. That's what keeps opening at 50-70 ms.
Since the container is now kept, the lyrics inside it can be kept too: built once, invisible and paused while closed (no TimelineView ticks, no lyrics or queue loading, no keyboard focus), shown again on ⌥⌘L, and re-centred on the current line when they come back.
There was a problem hiding this comment.
Fixed in f0080d4. The lyrics are now built a second after the window shows and kept. Closed, they are invisible and paused: their position TimelineView stops (lyricsAreShowing), they load no lyrics or queue and don't take the keyboard. Opening shows them again, back on the current line and with the keyboard in them.
Three runs of scripts/latency-test.sh --only lyrics.toggle on my Mac mini (Release, load average 5-7):
| run | median | checked | opening | closing |
|---|---|---|---|---|
| 1 | 36.7 ms | 47.6 ms | 35-52 ms | 32-38 ms |
| 2 | 38.3 ms | 39.6 ms | 39-40 ms | 29-38 ms |
| 3 | 33.7 ms | 35.8 ms | 33-39 ms | 28-36 ms |
The first open is 36-39 ms too, since the lyrics are already built. With the lyrics closed the app takes the same CPU (about 2%) as before they were ever opened. Open it's about 32%, all of it the lyrics playing.
testOpeningAndClosingTheLyricsReRendersNothingElse now also checks that the lyrics are built before they first open and that the same lyrics view comes back on every open. On the previous commit it fails on both.
Screenshot mode, dark, open, and closed again at the same place in the 1000-song playlist:
Light:
| | `sidebar.toggle` | ⌘S hides or shows the sidebar | 81 | 83 | #672 | | ||
| | `queue.toggle` | ⌥⌘Q opens or closes the queue | 72 | 77 | #673 | | ||
| | `lyrics.toggle` | ⌥⌘L opens or closes the lyrics | 114 | 123 | #674 | | ||
| | `lyrics.toggle` | ⌥⌘L opens or closes the lyrics | 46 | 50-52 | fixed in #674 (was 114 / 123)† | |
There was a problem hiding this comment.
This row needs the times measured on a quiet Mac once opening is fixed: 50-52 ms checked is over the budget it says is met.
There was a problem hiding this comment.
Updated in f0080d4 with those three runs: 34-38 ms median, 36-48 ms checked.
|
Another look at the kept lyrics, fixed in fe9c827:
Two more runs of |
|
Another look, fixed in fb4610e:
|
4075910 to
32d7a3b
Compare
|
CI failed Fixed in 32d7a3b: The other CI failure, |
|
On how much room Every Mac run of |
|
CI caught the bar once more on the second open, and this time nothing else rendered with it: not its parent, so the player didn't change. Its one other input was the Rebased on 0.8.79; |
f909cbc to
2b30793
Compare
420fa27 to
40a55a6
Compare
|
The pre-merge CI run on 40a55a6 is green: unit tests, interaction latency (Release) and static audits, https://github.com/isaaclins/wax/actions/runs/45750825086. The same branch merged with today's |
6fe218f to
03cb0ef
Compare
|
Rebased on 0.8.94. Two things came up with what
Also: building the lyrics ahead is now only on for the app's window ( |
99a9923 to
b08445b
Compare
⌥⌘L took about 115 ms to open the lyrics and 190 ms to close them (#674). Every toggle ran the whole browser again: the sidebar, the page under the lyrics with every song row on screen, the player bar and the menu bar. Closing was slowest because the page had been swapped for an empty view and was built again from scratch. - Whether the lyrics are open is its own small published object. Only the lyrics layer, the toolbar, the window's name, the bar's Lyrics buttons and the menus observe it; the browser and the scene host no longer re-render. - The page stays built under the lyrics, faded out and out of reach of the keyboard and VoiceOver, so closing shows it again at once where it was. The scroll-restore path that put a rebuilt playlist back in place is gone. - The lyrics' container and hosting view are built once and kept, hidden while closed, instead of a new view graph on every open. - The toolbar, the window's name, the bar's Lyrics buttons, the menus, the page's disabled state and the keyboard handoff follow one frame after the lyrics themselves, so they don't hold back the frame that answers the key. - The song list keeps its focus state in a small modifier, so a move of the keyboard no longer runs the list and its rows again.
…time after the fix
…ws them Opening still took 51-72 ms on a quiet Mac: each ⌥⌘L built the lyrics from nothing, every line, its text and the views inside, and that was most of the first frame. The lyrics are now built a second after the window shows and kept. Closed, they are invisible and paused: their position timeline stops, they load no lyrics or queue and take no keyboard focus. Opened again, they start on the current line and take the keyboard, as before. Opening now takes 33-52 ms, closing 28-38.
The kept lyrics hid their timing-hold view only once their fade had ended, so for 0.3 s after closing, a right click on a song under them started a timing hold instead of the song's menu. Holds now start only while the lyrics are open, and closing them ends one in progress. The comments on closed lyrics now say what they still load: the backdrop's artwork.
… load The lyrics' position reader swapped a timeline for a still view whenever playback started or stopped, which built every line again. With the lyrics now kept while closed, that happened on every play and pause even with them closed. It is one timeline now, paused while the song is or the lyrics are closed. A new test checks that closed lyrics fetch nothing when the song changes and that opening them loads the song playing then. Four browser tests now get the settings store the app always has: the lyrics built a second after the window shows need it, and one of them crashed without it.
The bar held the lyrics' open state as an @binding built from a getter. SwiftUI reads such a binding again whenever it updates the view, and its value changes on every ⌥⌘L, so any other update of the bar after a toggle ran the whole bar again. On CI that showed up as one bar render in testOpeningAndClosingTheLyricsReRendersNothingElse. The bar only writes the state; its Lyrics buttons read it through their own observer. The test now also says what else re-rendered.
The Interaction latency job on this branch measured 37-73 ms for ⌥⌘L, median 48. With the old 547 ms reference CI would only have caught it getting slower than about a second.
CI still caught one render of the bar when the lyrics opened a second time, with nothing else rendering: not its parent, so not the player. The bar's one other input was the openSettings action from the environment, which the window passes down again when the keyboard moves into the lyrics. Only the reconnect button needs it, so it reads it itself now. While a test counts renders, the bar now prints what made it run, so the next render CI catches says why.
The kept lyrics' timing-hold monitor still looked at every scroll and Esc in the window while they were closed. Both only matter during a hold, and closing the lyrics ends one, so the monitor now lets them pass untouched while the lyrics are closed.
main removed AppKitTestSupport.settleRunLoopOnly() (#746). This test is synchronous, so the plain settle() is the same barrier.
…e note Building the lyrics a second after the window shows needs the settings store the app always provides. Browser tests that host the window without one crashed once the lyrics built (SidebarToggleRenderScopeTests on CI), and each new such test would again. Building ahead is now the controller's buildsLyricsAhead, on for the app's window and for the test that checks it; everywhere else the lyrics build on their first open, as before. docs/latency.md: #673's queue row and note were overwritten when both used †; the lyrics note is ‡.
…stay built Since #599 a song whose lyrics failed for want of a connection waits for it and loads again when the network comes back; leaving the window ended that wait (onDisappear). The kept lyrics never leave it, so after closing them the wait went on and the song loaded behind them. Closing now ends it too. testClosingLyricsStopsTheirWaitForTheConnection fails without the change.
#701's test watched LyricsOverlayController.isPresented, which this branch moved into presentation (what the lyrics observe) and chromePresentation (what the menus follow).
#701 compared a copy of it taken when the browser ran. The browser no longer runs when the lyrics open or close, so that copy went stale and a later page change rebuilt the bar for it. The bar's Lyrics buttons follow the lyrics through lyricsPresentation.
b08445b to
b5db122
Compare




Fixes #674. ⌥⌘L now opens or closes the lyrics within the 50 ms budget. Before this it took 115 ms to open and 190 ms to close.
How it looks
Nothing looks different. The lyrics and the page underneath end up exactly as before; they just show up sooner. Screenshot mode, after the change:
Times
scripts/latency-test.sh --only lyrics.toggle, Release build, my Mac mini M4, 60 Hz, 8 tries per run (4 opens, 4 closes), in ms with one frame included, load average 3-7:main(fromdocs/latency.md)Timed back to back with
mainat 0.8.73 on the last commit: this branch 39.8 / 39.5 ms median, 43.0 / 43.2 checked;main145 / 150 median, 170 / 178 checked. Play/pause is the same on both (see the comments; its creep since 0.8.68 is #726).The first open is as quick as the others, since the lyrics are already built by then.
lyrics.toggleis off theknownlist inscripts/latency-baseline.json, itscitime there is 48 ms (from 547) after this branch's CI run measured 37-73 ms, anddocs/latency.mdhas the new time.What was slow
Profiles of the press-to-first-frame window showed the main thread busy the whole time, and very little of that was the lyrics themselves:
@PublishedonLyricsOverlayController.PlaylistBrowserViewheld it as an@EnvironmentObject, and the scene host passed every change on toRootView. So each ⌥⌘L rebuilt the sidebar, the page under the lyrics with every song row on screen, the player bar and the menu bar.NSHostingViewwere created and added to the window each time.NSHostingView.layout()building every lyric line, its text, the focus modifiers and the AppKit views inside.@FocusStatelived inTrackListView, so the lyrics taking the keyboard ran the list body and every row again.The change
LyricsPresentationState. Only the lyrics layer and the page's fade observe it. The controller itself publishes nothing, andRootViewno longer hears about it.pendingScrollRestoreTrackID, the first-visible-row tracking inTrackListView, the anchor helper) is gone.lyricsAreShowingin the environment): their positionTimelineViewstops, and they load no lyrics or queue and take no keyboard focus. Opened again, they start on the current line and take the keyboard. With the lyrics closed the app uses the same CPU (about 2%) as before they were first opened.LyricsPresentationStateset right after Core Animation commits. They used to change in the same frame.TrackListViewkeeps its focus state in a small modifier.Tests
WindowResizeCostTests.testOpeningAndClosingTheLyricsReRendersNothingElsehosts the real browser on a 500-song playlist, then opens and closes the lyrics twice. It fails if the browser, sidebar, page column, page, player bar or any song row runs its body again. It also checks that the window's name and the toolbar still switch, that the lyrics are built before they first open, and that the same lyrics, not just their container, come back on every open and are hidden once closed. On the code before this change it fails on every toggle.LyricsOverlayControllerTests.testTheFrameAroundTheLyricsFollowsOneFrameLaterchecks the toolbar state follows one frame later, and that an open and close within one frame doesn't swap the toolbar twice.make test: 2559 tests, 0 failures.scripts/check-periphery.sh(periphery 2.21.2) reports onlySpotiglassSettingsView.columnVisibility, whichmainreports too.What I couldn't check
LyricsOverlayController(it publishes only on a real change, which this does too) and the player bar. Whichever lands second needs a small merge.