Skip to content

Add interactive Graphite performance lab - #4885

Closed
mattleibow wants to merge 2 commits into
mainfrom
mattleibow-graphite-performance-sample
Closed

mattleibow wants to merge 2 commits into
mainfrom
mattleibow-graphite-performance-sample

Conversation

@mattleibow

Copy link
Copy Markdown
Contributor

Description

Adds Graphite Performance Lab, a native macOS/Metal sample for exploring what Skia Graphite parallel recording does—and does not—improve in an onscreen UI workload.

This began as a request to demonstrate a credible “10x” Graphite improvement. The investigation found that a blanket throughput claim would be misleading: Ganesh remains faster for many mature UI primitives, while Graphite’s architectural advantage is moving independent CPU command preparation off the UI/submission thread and making GPU pipeline behavior more predictable. The final app therefore reports the work honestly instead of optimizing a hidden microbenchmark.

Research trail and conclusions

  1. A prior Vulkan comparison found Graphite behind Ganesh on much typical UI content, but ahead by about 28% for a 2,000-sprite DrawAtlas workload. Parallel Recorders recovered roughly 20% on suitable vector scenes but hurt text-heavy scenes where shared glyph resources contend.
  2. An initial offscreen harness showed a large reduction in submission-thread work and a smaller end-to-end improvement. That harness was intentionally replaced: an offscreen benchmark did not demonstrate real window presentation or UI responsiveness.
  3. The replacement app uses two real MTKView drawables, real Metal command queues, onscreen composition, and interactive workloads.
  4. Running both views live side by side exposed a methodology bug: both callbacks share AppKit’s UI thread, so a slow Ganesh callback throttled Graphite. The app now defaults to Isolated A/B, quiescing and draining one backend before measuring the other while keeping both last-presented images visible. Live side-by-side remains available and is explicitly labeled contended.
  5. Graphite can present the last completed content faster than workers produce new content. The app therefore reports present FPS separately from content updates/s.

What parallel recording actually means

flowchart LR
    subgraph CPU["CPU: parallel command preparation"]
        W1["Worker 1<br/>SKCanvas.Draw*"] --> R1["Recorder 1<br/>Snap()"]
        W2["Worker 2<br/>SKCanvas.Draw*"] --> R2["Recorder 2<br/>Snap()"]
        WN["Worker N<br/>SKCanvas.Draw*"] --> RN["Recorder N<br/>Snap()"]
    end

    R1 --> C["AppKit / Context thread<br/>InsertRecording in dependency order<br/>record composition<br/>Submit"]
    R2 --> C
    RN --> C
    C --> Q["One ordered<br/>MTLCommandQueue"]
    Q --> G["GPU command processor"]
    G --> P["Many shader lanes,<br/>raster units, samplers,<br/>and fixed-function stages"]
Loading

Each worker exclusively owns an SKGraphiteRecorder, Graphite surface, and painter. Snap() produces a transferable SKGraphiteRecording containing prepared Graphite tasks/resources—not a native Metal command buffer. The AppKit/Context thread serially inserts completed recordings, records the final tile composition, submits one ordered Metal stream, and presents the drawable.

Multiple Recorders do not create multiple GPU queues. One ordered queue also does not mean a single GPU execution thread: queue ordering preserves dependencies while the GPU executes shaders and fixed-function stages across many hardware lanes. The useful overlap is:

CPU workers: prepare content update N + 1
AppKit:      compose and present update N
GPU:         execute submitted update N

The companion lifecycle/architecture documentation is in #4566.

UI-framework mapping

The default dashboard models an Uno/Avalonia-style retained UI compositor conceptually; it does not claim existing Uno controls use Graphite. Each tile represents an independently invalidated raster root such as a scrolling region, popup, chart, window, or expensive visual subtree. Workers prepare dirty roots, the Context thread inserts completed recordings in dependency order, and the compositor combines updated and cached roots into the window.

This pattern is strongest when work divides into several substantial independent roots. Dependencies, tiny jobs, shared text/image caches, or an already GPU-bound scene can erase the benefit.

Included workloads and controls

  • UI dashboard: cards, labels, charts, status points, lines, rounded rectangles, and progress bars using normal UI drawing primitives.
  • Vector tiles: DrawRoundRect, DrawOval, DrawLine, and DrawArc state churn.
  • Sprite atlas: batched DrawAtlas sprites—the clearest outright Graphite win in the earlier investigation.
  • Text grid: deliberately stresses shared glyph resources and demonstrates a workload that may scale poorly.
  • Controls for 1–8 roots/workers, 100–8,000 items per root, animation, 15–120 Hz, isolated A/B, either backend alone, and explicitly contended live side-by-side.
  • Metrics for presented frames, content updates, full UI callback cost, and serial/parallel preparation critical path.
  • --screenshot mode captures the app-owned window without terminal screen-recording permission.

Exploratory observations

Host: Apple M3 Pro (36 GB), macOS 26.6.1.

  • The attached default run (6 UI roots × 4,000 items, 60 Hz target) shows both backends sustaining 60 updates/s, while Ganesh spends about 15.6 ms in its serial UI callback versus roughly 0.5 ms of Graphite UI-thread work; Graphite’s worker critical path is about 5 ms.
  • In an interactive high-load run (8 roots × 8,000 Sprite Atlas items, 120 Hz target), Ganesh was observed around 20 updates/s and isolated Graphite around 120 updates/s.

These are exploratory device-specific observations, not BenchmarkDotNet claims. The app exists so results can be reproduced across hardware, workload types, partition counts, and future Skia milestones.

Related issues

None. Related documentation: #4566.

Required skia PR

None.

Areas affected

  • Managed API (binding/)
  • Native / C API (externals/skia/src/c, include/c)
  • Generated P/Invoke bindings
  • Native dependency or Skia update (libpng, HarfBuzz, FreeType, zlib, milestone bump, …)
  • Views & integrations (MAUI, Uno, WPF, WinUI, Blazor, …)
  • Rendering output / visual behavior
  • Performance
  • Tests
  • Build, packaging, or CI
  • Documentation or samples

Changes

None — sample-only change. No public API, ABI, package behavior, or existing application behavior changes.

Testing

  • Downloaded the current milestone’s prebuilt native binaries with dotnet cake --target=externals-download (no native/C API changes in this PR).
  • Merged current origin/main (6386960c2a4) into the branch.
  • Built the macOS ARM64 app in Release with net10.0-macos; build completed with 0 warnings and 0 errors.
  • Launched the generated .app, exercised isolated A/B and live rendering, and sampled the process. Runtime stacks showed gr_direct_context_flush_and_submit, six named Graphite tile Recorder OS threads, Graphite Snap/recording activity, Context insertion, and Metal presentation.
  • Generated and inspected the self-captured app screenshot; both Metal panels contain the same rendered dashboard and independent metrics.
  • Full required console suite: 6,134 passed, 23 skipped, 3 failed. Two transient stream/GC failures passed immediate focused reruns. The remaining ganesh-gl/DiagonalLines macOS golden mismatch reproduces independently and is unrelated to this sample-only diff; this branch changes no binding or test code.
  • No automated test was added because this is an interactive, hardware-dependent Metal investigation sample. Correctness is covered by build, live execution, identical visual content, explicit failure surfacing, and the existing Graphite/Ganesh test infrastructure.
Screenshots (before / after)
Before After
N/A — new sample Graphite Performance Lab showing isolated Ganesh and Graphite Metal panels

Checklist

  • Tests added or updated — omitted because this is an interactive hardware-dependent sample; manual and existing-suite validation are documented above.
  • Changes above lists all public API and behavioral changes (or "None.")
  • New/changed public API? N/A — no public API changes.
  • Native change? N/A — no native/C API or submodule changes.

Copilot AI added 2 commits August 28, 2026 00:50
Add a macOS Metal sample that compares Ganesh's serial command preparation with Graphite's worker-owned Recorders using the same onscreen workloads. Separate present rate from content-update rate, provide isolated A/B and explicitly contended side-by-side modes, and document the CPU recording, serialized submission, and GPU execution model.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 9c660d23-bc1a-4e17-b1f3-b6d1072ed0df
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 9c660d23-bc1a-4e17-b1f3-b6d1072ed0df
@github-actions

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 4885

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 4885"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-4885/packages --name skiasharp-pr-4885
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-4885

@github-actions

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

The documentation for this PR has been deployed and is available at:

🔗 View Staging Site
🔗 View Staging Docs
🔗 View Staging Gallery (Blazor)
🔗 View Staging Gallery (Uno Platform)
🔗 View Staging SkiaFiddle

This preview will be updated automatically when you push new commits to this PR.


This comment is automatically updated by the documentation staging workflow.

@github-actions

Copy link
Copy Markdown
Contributor

📊 SkiaSharp benchmarks — PR #4885

No ⭐ source-build (pr) benchmark results were produced for this run, so there is nothing to compare yet. The source-build legs are best-effort and may be skipped (native unchanged) or may have failed — see the run for details.

📈 View the benchmark run & perf-dashboard artifact →

@github-actions

Copy link
Copy Markdown
Contributor

📦 Artifact size report

Packages from this PR (build 1571526) vs the latest nightly baseline 4.152.0-nightly.47 (observed 2026-08-27).

Total .nupkg size: 569.6 MB → 569.1 MB (−601.9 KB, -0.1%)

Packages

⚠️ marks growth over 500.0 KB or 2%. Changes under 50.0 KB are treated as noise.

Package baseline this PR Δ Δ%
SkiaSharp.NativeAssets.WinUI 109.1 MB 108.3 MB 🟢 −753.3 KB -0.7%
SkiaSharp.NativeAssets.WebAssembly 69.7 MB 69.7 MB 🔴 +84.8 KB +0.1%

+39 package(s) unchanged (< 50.0 KB).

Per-file changes

SkiaSharp.NativeAssets.WinUI

File Size
runtimes/win-arm64/native/libGLESv2.pdb 64.5 MB → 64.4 MB (🟢 −128.0 KB)
runtimes/win-x86/native/libGLESv2.pdb 67.3 MB → 67.2 MB (🟢 −80.0 KB)
runtimes/win-x64/native/libGLESv2.pdb 66.6 MB → 66.6 MB (🟢 −64.0 KB)

Informational only — this never blocks the PR. Native binaries are labelled by os/arch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants