Skip to content

perf(desktop): draw shadows on the GPU and cap Skia's texture cache - #531

Merged
linroid merged 1 commit into
mainfrom
perf/desktop-memory
Oct 13, 2026
Merged

linroid merged 1 commit into
mainfrom
perf/desktop-memory

Conversation

@linroid

@linroid linroid commented Oct 13, 2026

Copy link
Copy Markdown
Owner

What changed

Using the desktop window grew the app past 1 GB, almost all of it graphics; the Java heap stayed around 40 MB.

  • Shadows: Compose's Modifier.dropShadow blurs 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. ketchSurface now draws its shadows with elevationShadow: on Skia (desktop, iOS and web, in a new skikoMain source set) a blurred shape that Skia draws on the GPU from a small cached profile, whatever the size. Android keeps dropShadow, because its hardware canvas ignores blur mask filters before API 28.
  • Skia's GPU cache: the launcher caps it at 64 MB with -Dskiko.gpu.resourceCacheLimit=64M (Skia's default is 256 MB, which nothing gives back while the window shows).
  • One jar: release builds join the ProGuard output into a single desktop.jar (joinOutputJars). ProGuard keeps only the first copy of a file that several jars carry, which dropped OkHttp's META-INF/services/io.ktor.client.HttpClientEngineContainer. A step after ProGuard writes each service file from every input jar again, in the old classpath order, so ServiceLoader finds 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):

Build After use Peak GPU Large mallocs
main 1131 MB 1363 MB 364 MB 234 MB
main + 64 MB GPU cache only 956 MB 1190 MB 192 MB 256 MB
GPU shadows only 865 MB 963 MB 434 MB 0
This PR (two runs) 686–717 MB 811–841 MB 234–256 MB 0

An 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 uses dropShadow. Across all 177 shell, palette, intake and toast snapshots, no channel changes by more than 9 of 255.

Before After

Testing

  • ElevationShadowTest renders 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:jvmTest passes (2,311 tests). compileKotlinWasmJs, compileAndroidMain and compileKotlinIosSimulatorArm64 succeed.
  • createReleaseDistributable gives one desktop.jar beside libskiko-macos-arm64.dylib. Its HttpClientEngineContainer lists CIO then OkHttp, and the packaged app starts and restores its engine.

For reviewers

  • A generic-path shape with a negative spread is drawn without the shift and crop dropShadow gives it. No surface uses one: they are all rounded rectangles.
  • Not covered: memory under heavy HTTP or torrent downloads. Most of the remaining ~700 MB is window buffers and the JVM's base cost.
  • Follow-up: drop the CIO client in favour of OkHttp, which already carries proxies, interface binding and Discover.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T00:47:01.201658Z e0b11c9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 861 files  +1   1 888 suites  +1   21m 24s ⏱️ -6s
12 534 tests +2  12 290 ✅ +2  244 💤 ±0  0 ❌ ±0 
14 973 runs  +2  14 729 ✅ +2  244 💤 ±0  0 ❌ ±0 

Results for commit e0b11c9. ± Comparison against base commit 4ab6d72.

@linroid
linroid merged commit 1bde68b into main Oct 13, 2026
15 checks passed
@linroid
linroid deleted the perf/desktop-memory branch October 13, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant