[GUI] Avoid per-command clip array cloning and redundant SKPath allocations in SurfaceRecorder

Open
#224 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Zaldaryon is already working on this.

Since Nov 6, 2026.

  • #234 by @Zaldaryon — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
performance

Research direction

Read sources/Cairo/wrapper/SurfaceRecorder.cs and sources/Cairo/wrapper/RecordedGuiDrawing.cs, then inspect RecomposeBenchmark to understand the reported GPU and CPU allocation measurements. The issue proposes sharing clip snapshots and fast paths for axis-aligned rectangles, but a linked pull request is already open. Done means reducing the reported allocations while preserving recorded drawing behavior.

Written by the indexing model from the issue text.

Description

complexity: medium performance rendering

Problem

In RecomposeBenchmark, 10 inventory recompositions allocate 117.5 MB on the managed heap in Skia GPU mode (~3.9 MB per recompose, exceeding the 78.6 MB allocated by the CPU fallback path). Key contributors in sources/Cairo/wrapper/SurfaceRecorder.cs and sources/Cairo/wrapper/RecordedGuiDrawing.cs include:

  • CaptureClips() and Save() clone clips.ToArray() across recorded draw commands even when the active clip stack has not changed since the previous command.
  • SurfaceRecorder.TrySeal copies commands.ToArray() and resources.ToArray().
  • Simple geometry primitives (axis-aligned rectangles and lines) allocate full SKPath clones for recording and replay.

Proposed Fix

  • Use copy-on-write sharing for RecordedGuiClip[] snapshots so consecutive draw commands that share the same clip state reference the same immutable array instance.
  • Fast-path axis-aligned rectangle fill/stroke/clip commands in SurfaceRecorder and RecordedGuiDrawing without allocating intermediate SKPath instances.
Dominant language
C#
Stars
22
Forks
4
Avg merge
1h 11m
Merged PRs (30d)
40

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StratumServer/Optimum

All issues in StratumServer/Optimum

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.