Repository navigation
Commit 9f6b1cd
authored
fix(zero-swift): stop macOS virtual list rows laying out on every scroll frame (#202)
Flinging zbugs-swift's issue list on macOS, every row the list kept laid
itself out on every frame: about 52 NSHostingView layouts a frame, three
in four of them off screen. Each row's hosting controller followed the
safe area (the default on macOS; iOS already turned it off), so as the
list scrolled, AppKit's update-constraints pass ran each row's
SizeConstraints.update -> minSize() -> updateSafeArea(), then its layout
and render. In a Time Profiler trace of fast flings that was about 17% of
the main thread. Rows now take no safe area on either platform; they draw
the same (screenshots before and after match, but for the menu bar clock).
A layout pass also looked each row near the screen up with a linear
first(where:) over the snapshot's rows, every time it stacked them: 3-4%
of the main thread. RowsLayout now keeps each row's position by key.
Release builds on a Mac satellite (60 Hz display, 155 open issues), the
same scripted trackpad flings (about 36,000 pt), three alternating runs:
- row layouts a frame: 52 -> 0.5 (0.87 -> 0.23 ms a frame)
- main thread busy over 4 ms: 1177 / 1199 / 1177 -> 349 / 351 / 381
- over 8.3 ms (a 120 Hz frame): 166 / 171 / 158 -> 117 / 135 / 146
- over 16.7 ms: 17 / 18 / 18 -> 12 / 11 / 10
- frames dropped at 60 Hz: 12 / 9 / 11 -> 12 / 9 / 7
The stalls left over 8.3 ms are measuring rows that come into reach
(SwiftUI sizeThatFits) and page changes (the virtualizer reopening its
queries from didScroll inside the layout pass).
Amp-Thread-ID: https://ampcode.com/threads/T-02a95685-6d19-4dd4-b1de-8210ec5599df
Co-authored-by: tmm <tmm@tmm.dev>1 parent 16ee0b8 commit 9f6b1cd
2 files changed
Lines changed: 21 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| 159 | + | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
160 | 169 | | |
161 | 170 | | |
162 | 171 | | |
| |||
283 | 292 | | |
284 | 293 | | |
285 | 294 | | |
286 | | - | |
287 | | - | |
| 295 | + | |
288 | 296 | | |
289 | 297 | | |
290 | 298 | | |
| |||
308 | 316 | | |
309 | 317 | | |
310 | 318 | | |
311 | | - | |
| 319 | + | |
312 | 320 | | |
313 | 321 | | |
314 | 322 | | |
| |||
445 | 453 | | |
446 | 454 | | |
447 | 455 | | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
448 | 460 | | |
449 | | - | |
450 | 461 | | |
451 | 462 | | |
452 | 463 | | |
| |||
0 commit comments