Repository navigation
perf(zero-swift): draw VirtualList's debug tint and TestHost's header in a shape; warn about bare-style backgrounds on macOS 27 - #284
Merged
Conversation
… in a shape, and warn against bare-style backgrounds on macOS 27 On macOS 27, a hosting view whose content has a background or an overlay drawn from a bare ShapeStyle resolves its safe area against the window's corners and so follows its geometry in the window. Every scroll of the clip view then invalidates it, and the invalidation reaches the window's root hosting view through SwiftUI's platform view host: the root and that view lay out again on every frame the list scrolls. macOS 26 doesn't do this, whichever SDK the app is built with. TestHost's header used .background(.quaternary), so the frame probe measured this instead of the list. It now draws in a Rectangle, which renders the same pixels. The debug blank-space tint draws each row's backdrop the same way, and VirtualList's docs tell apps to. Amp-Thread-ID: https://ampcode.com/threads/T-884aab88-be49-4bc7-96a1-044f0e71dabf Co-authored-by: tmm <tmm@tmm.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Option D of the perf sweep: why macOS laid the window's root out 3–5 times per moving frame, against 0.36 on iOS.
Cause. On macOS 27, a hosting view whose content has a background or an overlay drawn from a bare
ShapeStyle(.background(.quaternary), aColor, a material) resolves its safe area against the window's corners (_BackgroundStyleModifier.BackgroundInfo→SafeAreaInsets.resolve(regions:cornerAdaptation:in:)→NSHostingView.rootTransform), which registers the view for changes to its geometry in the window. Every scroll then invalidates it (NSClipView.scrollToPoint→NSViewHierarchyNoteGeometryInWindowDidChange→NSHostingView.geometryInWindowDidChange). ItssetNeedsUpdateConstraintsreaches SwiftUI'sAppKitPlatformViewHost, which invalidates the window root's layout. TestHost's header was such a view. Rendering each snapshot,updateNSView, and resetting the header's and footer'srootVieware not involved.macOS 26.3 doesn't do this. macOS 27.2 does, whether the app is linked against the 26.5 or the 27.3 SDK. A standalone harness shows it: 200 hosting-controller rows in an
NSScrollView, scrolled by script. Rows with a bare-style background cost 7.0–7.5 ms per step there, against 0.8 ms for the same rows in aRectangle. No public modifier or hosting option tried (ignoresSafeArea,safeAreaPadding,compositingGroup,containerShape,sceneBridgingOptions = [], hiding the view, and others) stops it, so ZeroVirtual can't avoid it on an app's behalf.Change.
.background(.quaternary, in: Rectangle()), so the frame probe measures the list.-ZeroVirtualTintBlankSpace YES) draws each row's backdrop in aRectangle.VirtualList's docs: draw backgrounds and overlays in rows, the header and the footer in a shape.Release builds behave the same. ZeroVirtual itself doesn't get faster: an app whose list content uses bare-style backgrounds keeps paying until it changes that content. zbugs-swift's list content already uses shapes (
in: Capsule(),in: RoundedRectangle).Same pixels. Window captures of TestHost's issue list, main against this branch on macOS 27, are identical files in light, in dark, and in dark with the debug tint on. A harness also rendered
.background(style)and.background(style, in: Rectangle())identically for.quaternaryand the window background, in light and dark.Numbers. TestHost's issue list with SwiftUI rows, Release, macOS 27.2 on a Mac satellite (mac.large). main (2cc09db) and this branch ran in turns, alternating which went first.
layoutscounts SwiftUI's hosting views' layouts (the list's and the window root's) per frame the list moved (-probe-layouts 1). Busy is the main thread's time per frame, from runs without the counter.issues: layouts per moving frameissues: busy ms per frame, 3 roundsissues: frames over 16.7 msblanking -latency 50: layouts per moving frameblanking: busy ms per frame, 3 roundsblanking: frames over 8.3 ms / 16.7 ms-ZeroVirtualTintBlankSpace YES,issues: layouts per moving frameThe macOS root now lays out about as often as iOS's (0.36). Wrong and blank frames don't change:
issues0 and 0 on both;blankingwrong 39–51 on main and 37–45 here, blank 0 on both.blanking's 120 Hz stalls barely move, because they come from page changes rather than from this.Tests. macOS 27:
swift test --filter ZeroVirtualTests, andswift format lint --strict.Patch changeset: the tint and the docs ship in the library.