Repository navigation
perf(desktop): draw shadows on the GPU and cap Skia's texture cache - #531
Merged
Merged
Conversation
Using the desktop window grew the app past 1 GB. Compose's Modifier.dropShadow blurs each shadow into a bitmap the size of its shape on the CPU and builds a new one whenever the size changes, so a resize, or a sheet or the inspector animating open, left a bitmap of several megabytes and its GPU texture for each size until a collection freed them, while Skia kept up to 256 MB of textures cached. - Surfaces draw their shadows with elevationShadow: on Skia (desktop, iOS, web; a new skikoMain source set) a blurred shape Skia draws on the GPU from a small cached profile, whatever the size. Android keeps dropShadow, whose hardware canvas ignores blur mask filters before API 28. ElevationShadowTest keeps both within 10 of 255 per channel. - The launcher caps Skia's GPU cache at 64 MB (-Dskiko.gpu.resourceCacheLimit). - Release builds join the ProGuard output into one desktop.jar. ProGuard keeps only the first copy of a file several jars carry, which dropped OkHttp's HttpClientEngineContainer, so a step after it writes each META-INF/services file from every jar again, in the old classpath order. A resize sweep, then the add sheet, palette, shortcuts, Discover and Settings, then a minute idle: 1131 MB after use and 1363 MB at peak before, 686 to 717 MB and 811 to 841 MB after.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
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.
What changed
Using the desktop window grew the app past 1 GB, almost all of it graphics; the Java heap stayed around 40 MB.
Modifier.dropShadowblurs every shadow into a bitmap the size of its shape on the CPU and builds a new one whenever that size changes. A window resize, or a sheet or the inspector animating open, left a bitmap of several megabytes plus its GPU texture for each size until a GC freed them.ketchSurfacenow draws its shadows withelevationShadow: on Skia (desktop, iOS and web, in a newskikoMainsource set) a blurred shape that Skia draws on the GPU from a small cached profile, whatever the size. Android keepsdropShadow, because its hardware canvas ignores blur mask filters before API 28.-Dskiko.gpu.resourceCacheLimit=64M(Skia's default is 256 MB, which nothing gives back while the window shows).desktop.jar(joinOutputJars). ProGuard keeps only the first copy of a file that several jars carry, which dropped OkHttp'sMETA-INF/services/io.ktor.client.HttpClientEngineContainer. A step after ProGuard writes each service file from every input jar again, in the old classpath order, soServiceLoaderfinds the same providers first to last.Memory
Measured on Apple Silicon with the release build, in a separate data directory, with a driver that resizes the window 60 times over 12 s, then opens the add sheet, palette, shortcuts, Discover and Settings, then idles for a minute (
footprint -p):mainmain+ 64 MB GPU cache onlyAn idle launch through the packaged launcher settles at about 425 MB, down from roughly 500–580 MB.
Snapshots
Each "before" render differs from its "after" only in
Surfaces.kt, which still usesdropShadow. Across all 177 shell, palette, intake and toast snapshots, no channel changes by more than 9 of 255.Testing
ElevationShadowTestrenders every elevation (light and dark) and a strong shadow of each shape kind with both modifiers. Real elevations differ by at most 4 of 255 per channel, opaque test shadows by at most 9.:app:shared:jvmTestpasses (2,311 tests).compileKotlinWasmJs,compileAndroidMainandcompileKotlinIosSimulatorArm64succeed.createReleaseDistributablegives onedesktop.jarbesidelibskiko-macos-arm64.dylib. ItsHttpClientEngineContainerlists CIO then OkHttp, and the packaged app starts and restores its engine.For reviewers
dropShadowgives it. No surface uses one: they are all rounded rectangles.