Repository navigation
Text in a list's rows rasterizes from 4,096 pixels on the Mac, so scrolling a grid of cards stops drawing labels on the main thread - #2274
Conversation
ccheever
left a comment
There was a problem hiding this comment.
Thanks. The measurement is convincing for a grid whose rows are kept. Merged with main, the 17 Mac test classes I ran (including TextRasterMacTests, RowReuseMacTests and CollectionMacTests) pass. Before this can land:
- The gate fails
seams.inList's walk up the superviews adds aNodeViewcast and a tree walk past the recorded counts (nodeViewCasts597 of 596,treeWalks591 of 589). I reproduced this withbun scripts/gate.mjs --seamson this PR alone. Main passes. The list could be told to the node when it mounts, as other row facts are, rather than found by walking up.
Astra (GPT-6.2 Astra) reviewed it too. These are its code traces, which I have not reproduced:
- A recycled row can show the previous item's label. Paint "A" in an 80×20 pt label at 2×, rebind the row offscreen to "B", and scroll it on screen before B's raster lands. The pending job has B's key while the view still holds A's surface, the urgent check accepts it, and
updateLayershows A on B's row (TextRasterMac.swift:141,NodeViewMac.swift:903). Before this change that label drew directly, so it could not happen. - Rows that mount mid-fling put a surface per label back on the main thread. This is the case the 16,384 cutoff guards. With VoiceOver on, Mac row reuse is off (
RenewMac.swift:54), so a fling past the mounted window builds fresh rows, and each label of 4,096 pixels or more misses the cache and rasterizes synchronously (TextRasterMac.swift:153). Please measure that case, or limit the lower cutoff to rows that are kept or reused. - An eager list keeps a surface per label it has shown. Scroll Carousel's 2,000-card strip end to end at 2×: each qualifying label keeps its surface after it leaves the viewport, even once the shared cache evicts its entry, so memory grows with the cards visited (
apps/carousel/app.contract:71,TextRasterMac.swift:379).
The inList cache holds up. Astra checked that kind == "list" is the list on the Mac, and in an AppKit probe, moving an ancestor between a list and a plain container in the same window sent viewDidMoveToWindow to the label both times.
🤖 Generated with Claude Code
A grid's card labels (125×32 and 125×20 pt) sat just under minPixels at 2× and were drawn on the main thread at every redisplay: about 1,500 CPU draws in a 30-fling scroll, and most of each frame's commit (4.7 ms p50). Rasterized they are drawn once on a worker: 37 draws, 1.8 ms. Only in a kept row: a row of a list that windows its rows and rebinds them (ListHosting.owns, row reuse on), which each node learns from the parent it mounts under (prepareToMount(under:)) rather than by walking up. An eager list's rows and rows built anew (VoiceOver or Switch Control on) keep 16,384. A renewed view drops its raster, so a rebound row never shows the old item's label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
957ed21 to
2d7bcae
Compare
|
Thanks. All four are addressed in
New test: Measured with the same driven grid scroll, now with two-cover cards: commit p50 4.9 ms, p95 6.0 ms, no frame interval over 25 ms. That's unchanged from the unscoped version, since the grid's rows are kept. Tests on our machine (macOS 26.6).
How this was made. Claude Opus 5.5 (Anthropic's model, running in Claude Code) made these changes and wrote this reply, at the direction of the account owner. |
ccheever
left a comment
There was a problem hiding this comment.
Thanks. Recording the parent at mount is the right shape, and seams now passes. Merged with main, the gate passes. Points 2 and 3 of my last review are fixed. Point 1 is fixed for ordinary mounts, and point 4 is partly fixed.
Before landing
inKeptRowcan recurse forever. It asksparent.inKeptRowbefore caching its own answer (TextRasterMac.swift:326). A detached node also keeps themountParentit was last given. So if two nodes ever record each other, the first uncached lookup recurses until the stack overflows. Astra (GPT-6.2 Astra) traced one way in: B is portaled under A, a shared-element flight lifts B, and B returns to its declared parent while A is portaled under B.placeChildrenskips the flying B, so B keeps A as its parent while A records B (PresenterMac.swift:1388,FlightsMac.swift:305). I have not reproduced that sequence. The recursion and the stale parent are in the code either way. Walk the parents in a loop that stops at a node it has already visited, or at a fixed depth, and clearmountParentwhen a node is removed.- Rows the runner won't rebind still get the lower cutoff. The runner builds fresh rows where a row can't be rebound, such as a row with a text input (
reuse.rs:33,:125).inKeptRowonly checks the session-widerowReuseflag, so a fling through such rows rasterizes each new label on the main thread. That is the case point 3 of my last review was about. Ask whether the row is actually rebound, not whether reuse is on. - An eager list inside a windowed list's fixed content inherits
true.inKeptRowaccepts any descendant of an owned list, and the runner places a list's fixed content beside its row wrappers (views.rs:195). An eager list in a fixed header therefore keeps a surface for every label it has shown. That is point 4 again, one level down. Stop the walk at the row wrapper, or at the first list it meets.
Smaller
- Native table cells and both staged attachment paths still call
prepareToMount()without a parent (TableFeedMac.swift:117,StagingMac.swift:54,:98). So labels in anNSTableViewrow keep 16,384, as before this change. If that's intended, a line ininKeptRow's comment would say so. The new test usestable: false. useRowReuse(false)called directly leaves aninKeptRowcached until the next epoch.RowReuse.adoptbumps the epoch, but the runtime's setter doesn't (Bridge.swift:390).
Astra found no leak: mountParent is weak, and forget() releases the raster.
🤖 Generated with Claude Code
`inKeptRow` walks the recorded mount parents in a loop to the first list and stops at a node it has visited. It counts a row only once the list has rebound it: a row the runner never rebinds (one holding a text input), rows built while reuse is off, and an eager list in a windowed list's fixed content keep 16,384. A node leaving its container forgets its parent, and staged mounts record theirs. The answer no longer reads the runtime's reuse flag, so `Runtime.rowReuse` is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I finished the last review's points on this branch (46d98c1, then a merge of main) so it can land:
One difference from your version: the first screenful keeps 16,384 until its rows are first rebound, since only a rebound row is known to stay built. Each fix has a test that fails on 2d7bcae. 🤖 Generated with Claude Code |
What happens. Scrolling a wide grid on macOS, each frame's Core Animation commit is mostly AppKit drawing card labels on the main thread. We hit it in a library grid: 278 cards in 18 columns, each card a cover, a one-line author (125×20 pt) and a two-line title (125×32 pt). In a 30-fling scroll the CPU drew about 1,500 times. It also redrew the empty button around each card's labels.
Cause. A paragraph rasterizes on a worker and shows as a layer only above
TextRasterizer.minPixels(16,384). At 2× scale those labels are 10,000 and 16,000 pixels, just under, sotextIsSmallsends them todraw(_:). The cutoff's comment explains it: a surface has a fixed cost, and a table that built one per narrow cell as each row mounted scrolled worse. That holds when rows are built mid-scroll. A list's rows are mostly kept and reused instead, so its labels are drawn again on the main thread at each redisplay, while a surface is made once.Fix. Text inside a list (any
listancestor;NodeView.inList, kept until the view moves) rasterizes fromminPixelsInList(4,096). Other text keeps 16,384.Measured. A driven macOS scroll of the grid above: 30 flings with turns, one phaseless continuous wheel event a frame, 60 Hz, card labels identical on screen.
NodeView.draw)Not measured. The narrow-cell table that motivated the cutoff. If that benchmark still exists, it's the case to rerun: a list whose rows mount while it scrolls now makes a surface per label of 4,096 pixels or more. Raising
minPixelsInList, or tying it to whether rows are kept, are the knobs if it regresses.Tests.
TextRasterMacTests,TextMetricsTestsandHDRColorTestspass. TwoPressWashMacTestsfailures (testCaptureCopiesOwnWhatAppKitDrewAgain,testOffscreenDrawingRestoresOwnedCanvasTextWithoutAnotherEdit) occur with and without this change on our machine (macOS 26.6). Tested onf032000129plus our other local patches. The diff applies toe65895d009.How this was made. Claude Opus 5.5 (Anthropic's model, running in Claude Code) found this, wrote the change, the tests and this description, and ran the measurements, at the direction of the account owner, who is opening the PR. The numbers come from runs on one Mac (macOS 26.6, 60 Hz display).