Repository navigation
Description
What happened
A sheet whose page has a fine diagonal texture made of repeating-linear-gradient layers is slow on iOS in two ways:
- Every open stalls. In a Release build on an iPhone 18 Pro simulator (iOS 27.0), opening such a full-height sheet held the main thread for 1.5 to 1.9 s, followed by a commit of about the same length. xctrace counted 22.5 B instructions, nearly all of them
ripc_DrawShadingunderNodeLayer.display(). - Every frame of a detent drag repaints the texture. Dragging the same sheet between
mediumandlargeran at 7 to 13 UI updates per second, with 58 to 127 ms per update spent inNodeLayer.display. An axis-aligned 14 px grid texture ran at 46 to 53.
All numbers are from the simulator. Neither was measured on a device.
Cause
The stall. Gradient.paintAxialRuns (host/apple/Sources/ExactKit/Gradient.swift) draws a gradient with hard stops as one drawLinearGradient per continuous run. Core Graphics shades each call over the whole clip, whatever the run's extent. So a repeating gradient costs the box's area times its stripe count, and a diagonal hatch across a phone screen has hundreds of runs.
The drag. A repeating-linear-gradient background makes the node draw its whole box in draw(_:) (gradientDraws → boxDrawn). The view's contentMode is .redraw, and UIKit resizes a sheet with detents on every frame of an interactive drag, so the full-size texture is rasterized again on every frame. Making each repaint cheaper does not change that.
How a fork fixed it
Two changes, both on Apple hosts only:
- Shade each run only where it falls (appandflow/exact@b7c16ebe1, about 30 lines in
paintAxialRuns). With more than eight runs, the clip is cut into 32-pixel tiles on the device grid, and each tile draws only the runs whose span along the gradient line crosses it. These are the samedrawLinearGradientcalls with the same options, so each pixel is shaded by the same run as before. Runs whose colours are all transparent are skipped. Eight runs or fewer, or a device transform with rotation, keep the whole-clip loop. The open went from 22.5 B instructions to 1.0 B, about 85 ms including the commit. The Chrome parityhatchcase inBorderParityMacTestsstays at 0.00/255. - Paint a repeating background as tiles on iOS, so a resize draws nothing (appandflow/exact#9). When every background layer is a repeating linear gradient whose period is the same at every box size,
Gradient.period(dark:)reads one period from the resolved stops, and the gradient paints as cached tile pictures on sublayers placed from the device pixel of the corner where the gradient line starts. Cells with the same phase share oneCGImage, so at 45° there is no seam or drift. The node keeps no bitmap, and a whole-pixel resize reuses existing pictures. A gradient with a percentage stop,to <corner>, mixed layers, linear-light interpolation, or a box that something else makes draw keeps the drawn path. The drag went to 54 to 60 updates per second, withNodeLayer.displayat 0.05 to 0.09 ms per update. The PR description has the measurements and the tile tests (GradientTileTests,GradientTilesIOSTests). macOS is unchanged.
Host
iOS (the run-shading cost applies to macOS too, since it is the shared Gradient.swift)
Smallest app that shows it
Open the sheet, then drag it between its detents.
routes nav
home "/"
menu "/menu"
component App
action follow(url: string)
nav = go(nav, url)
action back
nav = back(nav)
view
main navigationKey=`${top(nav).id}` navigationBack="back" navigate=follow width="100%" height="100%"
for e in stack(nav) key=e.id
if e.name == "home"
column navigationKey=`${e.id}` position="absolute" inset=0 padding=16
link href="/menu" testId="open-menu"
text "Open"
if e.name == "menu"
column navigationKey=`${e.id}` navigationPresentation="modal" navigationDetent="medium large" position="absolute" inset=0 padding=16 background-color="#fcfcfc" background-image="repeating-linear-gradient(-45deg, transparent 0 4.243px, #e6e6e6 4.243px 5.657px), repeating-linear-gradient(45deg, transparent 0 4.243px, #e6e6e6 4.243px 5.657px)"
text "Sheet"
This snippet compiles. The measurements above came from an app with the same structure, not from this exact snippet.
Exact commit
Measured on a fork based on a107143. The code described above is unchanged on upstream main at f3a4ace.
Activity
ccheever commentedon Nov 15, 2026
Part 1, shading each stripe only in the tiles it crosses, is being built now. Part 2 is decided, after a three-model panel: a repeating linear gradient is drawn as one period that the platform tiles. The period is rasterized axis-aligned and rotated with the pattern matrix, so every angle tiles, and its phase follows the view rather than the window, so a sheet drag or a Mac live resize draws nothing. Other paints keep drawing. Queued to build after part 1.
Posted by Claude Code on the maintainers' behalf.
A repeating gradient on Apple shades each stripe only where it falls
ccheever commentedon Nov 15, 2026
Part 1 is in b121e3d, using the tiling approach from appandflow/exact@b7c16ebe1, credited in the code and the commit.
paintAxialRunsnow shades stripes only where they fall. On an iPhone simulator (iOS 27, debug build), the issue's two hatch layers at 402×874 pt and 3× went from 2.2–4.3 s to 0.19–0.5 s. An iPad-sized box went from about 5 s to about 0.5 s. The hatch parity case is unchanged, and at phone size the opaque hatch is byte-identical. On large boxes some pixels did change, and checked against where CSS puts each stripe, the new output is the correct one: the old code drifted along the gradient. This stays open for part 2, a tiled period with a phase tied to the view.Posted by Claude Code on the maintainers' behalf.
ccheever commentedon Nov 15, 2026
Part 2 is in 3c5a260, which closes this. On Apple, each repeating linear gradient in a background is now its own sublayer. The kernel works out one period, that period is drawn once as a Core Animation pattern cell, and Core Animation tiles it. The sublayer is turned to the gradient's angle and its origin sits where a period starts, so the stripes stay with the view, and a resize only moves that origin. The code is shared by iOS, tvOS and macOS, so macOS live resize gets this too.
On an iPhone simulator (iOS 27), dragging the issue's sheet through its detents:
The main thread now keeps up, which is why there are more calls.
Compared with Chrome on screen at 3x, the mean difference out of 255 is 0.00 at 0°, 45° and 90°, 1.32 at 30°, and at most 2.92 elsewhere. The hatch parity tests pass on iOS and macOS. One limit remains: a gradient whose period or angle depends on the box's size (percentage stops,
to <corner>) draws a new cell on each resize. That is still far cheaper than redrawing the box. LLP 1066 is amended to match.Posted by Claude Code on the maintainers' behalf.
A repeating linear gradient background on Apple is a tiled pattern, s…