Skip to content

⌘A and shift-click in a long playlist no longer build every row - #710

Open
isaaclins wants to merge 1 commit into
mainfrom
fix/694-select-all-fast
Open

isaaclins wants to merge 1 commit into
mainfrom
fix/694-select-all-fast

Conversation

@isaaclins

@isaaclins isaaclins commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Part of #694: ⌘A is far faster but not reliably under 50 ms yet (see Numbers), so #694 stays open for the rest. It builds on #683's long-list test and row keys (merged).

How it looks

Nothing looks different. The selection draws the same as before; only how fast it gets there changes.

What was slow

When the table makes a selection itself (⌘A, shift-click), SwiftUI's list asks every row the selection adds how it selects (outlineViewSelectionDidChange → onSelectSideEffects → selectionBehavior(item:makeIfNecessary: true)), and that builds the row's view, on screen or not. ⌘A on 2,000 songs built all 2,000 rows. A selection written through the binding doesn't go through that.

What changed

  • TrackListSelectionShortcuts (in TrackListView.swift) sits behind the track list. It catches ⌘A on the list's table and a single shift-click on one of its songs before the table does, and sets the selection itself:
    • ⌘A selects every song.
    • A shift-click selects the songs from the last song clicked without shift to the clicked one, and keeps songs picked with ⌘-click before, as the table does. A second shift-click extends from the same song again and swaps only the range. After ⌘A or shift-arrow, a shift-click selects the range alone, as the table's did.
    • Its mouse-up is swallowed too, because the table selects on mouse-up as well.
    • A plain click, a ⌘-click, a ⌘-shift-click and double-clicks still go to the table as before. They add one row at most. A control-click (the right-click menu) leaves the selection and the shift-click start alone, as before. The anchor for the next shift-click follows every click and any selection of a single song (so arrow keys move it too).
    • It stays out of the way when the list is disabled (the lyrics cover the page). It also stays out of lists with both a header and a footer (the artist page's handful of top tracks), where a table row can't be mapped to a song safely.
  • Each selected row's right-click menu worked out the pin state and the artists of the whole selection up to five times per build. Every selected row on screen builds its menu again on each selection change, so with 2,000 songs selected that was tens of thousands of row look-ups. TrackOpsMenuItems now works each one out once per build. Nothing in the menu changes.

Numbers

make test-speed (LongListScrollCostTests, optimized build, 2,000-song playlist, clicks and keys posted through the app's event queue). My Mac was busy with other builds during these runs, so the absolute numbers are rough.

2,000-song playlist before (with #683) this PR
⌘A 8.7 s (5.4 s with #683's menu fix) 48.5 / 54.0 / 57.0 ms (median of 60 presses in a row: 39 ms)
Shift-click 30 songs 85 to 127 ms 21.9 / 22.1 / 22.6 ms
Rows built by ⌘A 2,000 under 50 (only the ones on screen)

With the shift-click changes from the review, on a quieter Mac: shift-click 30 songs 20.8 ms, ⌘A 47.1 ms, click another 23.6 ms, right-click 0.9 ms, pause 11.5 ms.

Other interactions in the same runs stayed where they were: click another song 25 to 28 ms, right-click 1 ms, play/pause 11 to 26 ms. The first click on a freshly opened list is still around 35 to 40 ms quiet and over 50 ms under load (#689).

⌘A is not reliably under 50 ms yet. It now costs exactly what setting all 2,000 songs in code costs (same median, measured side by side), so nothing in the ⌘A path itself is left. The rest is SwiftUI walking all 2,000 rows of the list on any selection change (ForEachList.applyNodes). Getting under it means changing how rows learn they're selected, which is more than this fix.

Tests

  • testClickingSelectingRightClickingAndPlayingShowWithin50ms now presses a real ⌘A and real shift-clicks through the app's event queue (scrolled to the clicked song, as someone would). It checks the range comes from the last clicked song, and that a second shift-click extends from the same song. It no longer exempts ⌘A and shift-click from the "fewer than 50 rows built" check. GitHub's runners don't hand posted events to the window, so there these steps are skipped and the report says so. Long playlists scroll and take clicks without stalls #683's fallback there (the table selects the clicked row) now only stands in for plain clicks.
  • The long-list test also adds a song the way a ⌘-click leaves it before the shift-clicks, and checks both shift-clicks keep it.
  • testShiftClicksKeepWhatTheTableKeeps replays click sequences I ran against a plain NSTableView (⌘-click then shift-click, shift-click after ⌘A, after shift-arrow, after a ⌘-click that takes a song out, after a ⌘-shift-click, after an arrow key) and checks the same songs come out. It runs everywhere.
  • testAShiftClickSelectsFromTheLastClickedSong checks the range itself (up, down, same song, no anchor, an anchor that left the list, songs picked with ⌘-click before), and runs everywhere.
  • make build, make test (2,763 tests on today's main, 0 failures; it runs the real ⌘A and shift-clicks above too, without the timing). make test-speed measured shift-click 30 songs 21.8 ms and ⌘A 55.1 ms earlier today; on the latest main it doesn't link at all (make test-speed doesn't link on main: undefined SwiftUI opaque type in the Release test bundle #782), so these times are from before the rebase.
  • Today's main moved the list's row bookkeeping out of TrackListView (Opening or closing the lyrics with ⌥⌘L takes about 140 ms #674); the shift-click state now lives in the catcher itself, which hears of selection changes when the list hands it the new selection.
  • testATableRowMapsToItsSongAroundHeaderAndFooterRows checks which song a table row is when a header sits above the songs (Home's top tracks) or a footer below them.
  • On today's main the list hands its selection on inside a closure (On macOS 26 opening or closing the queue still redraws the player controls and the song rows #751); the shortcut catcher reads it the same way so opening the queue still doesn't redraw every row.
  • scripts/check-periphery.sh (2.21.2): only columnVisibility, which my local Xcode reports on main too.

Checked in the running app

Release build, sample library, a 1,000-song playlist:

  • Click song 2, ⌘-click song 5, shift-click song 8: 2 and 5 to 8 are selected.
  • Control-click song 10 (its menu opens), close it, shift-click song 6: 2, 5 and 6. The menu didn't move where the range starts.
  • ⌘A: every song.

Not checked

@isaaclins isaaclins left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through this against the table's own selection behaviour. The ⌘A and shift-click speed-up is real and the menu change is fine, but two things need fixing before it goes in, plus one about what this closes.

  • A shift-click throws away songs picked with ⌘-click (line comment).
  • A control-click (the right-click menu) moves the shift-click start (line comment).
  • ⌘A measures 48 to 57 ms here, and #694's "done means" asks for within 50 ms. This PR shouldn't say it fixes #694: I'll change it to "Part of #694" and leave the issue open with what's left.

Comment thread Spotiglass/Views/TrackListView.swift Outdated
shortcuts.realizedRows.selectionAnchorID = id
return event
}
shortcuts.selection = TrackListSelectionShortcuts.extend(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the whole selection with the range. The table keeps songs picked with ⌘-click: I checked a plain NSTableView with clicks posted through the event queue. Click row 2, ⌘-click row 5, shift-click row 10 gives 2 and 5 to 10. Shift-click row 8 after that gives 2 and 5 to 8. With this change the first shift-click gives only 5 to 10 and row 2 is gone.

So ⌘-click a few songs and then shift-click a range, the way Finder and Music work, now loses the ⌘-clicked songs. The shift-click should add the range to the selection as it was after the last click without shift, and a second shift-click should swap only the range.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4b7068b. The first shift-click after a click without shift now takes the selection as that click left it and adds the range to it; a second shift-click swaps only the range. Songs from before that left the list are dropped. testAShiftClickSelectsFromTheLastClickedSong checks it, and the long-list test now adds a song as a ⌘-click would before its real shift-clicks and checks it stays, both times.

guard let table = table(at: event.locationInWindow, in: window),
let id = trackID(atRow: table.row(at: table.convert(event.locationInWindow, from: nil)), of: table)
else { return event }
guard modifiers.subtracting([.capsLock, .numericPad, .function]) == .shift, event.clickCount == 1 else {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A control-click lands here too: it isn't exactly shift, so it sets the anchor to the row it opened the menu on. The table doesn't move its anchor for a control-click. Right-click a song, then shift-click, and the range starts at the right-clicked song instead of the last song clicked. A control-click should go to the table without touching the anchor.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4b7068b: a control-click goes straight to the table and leaves the selection and the shift-click start alone.

@isaaclins

Copy link
Copy Markdown
Owner Author

Went over it again against how the table selects on its own.

Found and fixed:

Clicked through the running app too: ⌘-click then shift-click, control-click then shift-click, and ⌘A all select what the table would. make test passes (2,541 tests).

@isaaclins

Copy link
Copy Markdown
Owner Author

Another pass, against the same plain-table reference:

  • A shift-click after ⌘A or shift-arrow kept every song those had selected. It now selects the range alone, as the table did. The shift-click bookkeeping is its own small type now (TrackListShiftClick), and testShiftClicksKeepWhatTheTableKeeps replays the click sequences I ran against a plain NSTableView and runs everywhere.
  • Checked ⌘-shift-click against the table too: it adds its song alone and starts the next range there, which is what this does.
  • Rebased onto the current Long playlists scroll and take clicks without stalls #683, so the diff here is only this change again.

Two things this leaves, filed: after a shift-click upwards the arrow keys go on from the bottom of the range (#718), and a shift-click on the artist name in a row selects instead of opening the artist (#719).

make test passes (2,558 tests).

@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch from 1ae3255 to 7aae1a8 Compare November 25, 2026 12:33
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 6be4a5e to 2e0339c Compare November 25, 2026 14:46
@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch from 7aae1a8 to 8c06902 Compare November 25, 2026 14:47
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 2e0339c to 1ebf8dc Compare November 25, 2026 16:59
@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch from 8c06902 to 2b442ef Compare November 25, 2026 18:40
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 1ebf8dc to a9c6017 Compare November 25, 2026 20:57
@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch from f858515 to 3c1fa2f Compare November 25, 2026 21:28
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from a9c6017 to 3a3bc97 Compare November 25, 2026 23:37
@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch 2 times, most recently from 98a2ff2 to c6a3833 Compare November 26, 2026 01:25
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 3a3bc97 to 6d60010 Compare November 26, 2026 03:39
@isaaclins
isaaclins force-pushed the fix/655-long-list-scroll branch from c6a3833 to 6604214 Compare November 26, 2026 06:18
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 6d60010 to 12f58ee Compare November 26, 2026 08:29
Base automatically changed from fix/655-long-list-scroll to main November 26, 2026 10:40
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 12f58ee to 4cb69cb Compare November 26, 2026 13:12
@isaaclins
isaaclins force-pushed the fix/694-select-all-fast branch from 8a18159 to f25c40a Compare November 26, 2026 16:06

This branch has not been deployed

No deployments
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