Skip to content

perf(renderer): record a canvas once as it opens, and measure large canvases on Android - #108

Merged
LeslieOA merged 3 commits into
developfrom
perf/android-large-canvas
Nov 7, 2026
Merged

LeslieOA merged 3 commits into
developfrom
perf/android-large-canvas

Conversation

@LeslieOA

@LeslieOA LeslieOA commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Large canvases on Android, measured on a Samsung Galaxy A15 (SM-A155F, Helio G99, Mali-G57, 90 Hz, Android 16), release build. One change to the renderer: the canvas is recorded once as it opens, and only its images again when they load. Drawing is unchanged, pixel for pixel.

What the A15 shows

The benchmark's UI-thread frame rate stays at 89–90 fps throughout, but Skia replays and presents on threads of its own, so frames that reached the screen were counted outside the app (dumpsys gfxinfo for the TextureView's window, SurfaceFlinger for a SurfaceView), with each thread's CPU time from /proc.

Frames on screen per second, 4 s per phase, before → after this PR (one build, develop's recording or the new one chosen at launch):

pinch pan pan 8× pinch in double-tap
2,000 42 → 36 56 → 49 70 → 63 54 → 56 59 → 52
5,000 49 → 50 55 → 56 70 → 68 63 → 61 64 → 67
10,000 45 → 41 48 → 46 70 → 64 55 → 59 65 → 56
big-10000.canvas 48 → 48 65 → 57 63 → 59 58 → 62 62 → 54

These move by up to ±8 fps from run to run on the same build; neither column is faster. 500 nodes (develop): 42, 68, 67, 52, 51.

Real double-taps (input tap twice) on big-10000.canvas once it has opened, six zooms in and out each: 68–86 fps during the zoom, at most 3 frames over 25 ms, with either recording.

  • Size isn't the cause. 500 nodes are as slow as 10,000: Skia's picture culling replays only what's in view. On a phone every canvas of 2,000 nodes or more fits at the smallest scale, 0.1, which shows about 530 cards with their text.
  • Most of the gap is the presenting, not the drawing. With nothing to draw (an empty picture, no SVGs) the canvas still reaches only 59–71 fps on the A15, and a SurfaceView instead of the TextureView did no better (45–56). Leaving out the live SVGs moved the numbers by less than run-to-run variation (±8 fps).
  • The fitted scale lands either side of the overview. The benchmark's fit (an animated one) landed at 0.09999999999999998, just under 0.1, where the canvas draws its text-free overview, so its pinch and pan phases drew no text; pinch in and double-tap did. About a quarter of camera animations that end at 0.1 land just under it (a + (0.1 − a) × 1 in floating point).
  • Zooming costs more than panning. Drawing the fitted view offscreen takes 7 ms of CPU at a scale already drawn and 16 ms at a new one (text is rasterised again at each scale); the render thread's CPU rises from ~450 ms/s panning to ~550–700 ms/s zooming.
  • The JavaScript thread was held for seconds after a canvas opened, and a double-tap waits on it: its camera animation runs from that thread. This PR shortens that.

The change: one recording, in layers

The canvas was recorded twice as it opened (all of it, then again without text for the overview), and both again when its images finished loading. Each recording of 10,000 nodes held the JavaScript thread for 3.5–4 s on the A15.

The recording is now one Picture per layer (group cards, group images, edges and cards, text, file images, group labels), drawn one after another in the same order as before. The overview is the same layers less text, with nothing recorded again, and images that finish loading record only the two layers that draw them.

JavaScript thread held by recording after opening, A15, before → after:

at open when images load JS thread busy after the fit (benchmark)
2,000 nodes 1,057 → 733 ms 802 → 0 ms 3.3 → 2.5 s
5,000 nodes 1,976 → 1,642 ms 2,000 → 3 ms 7.1 → 4.7 s
10,000 nodes 4,095 → 3,500 ms 3,835 → 3 ms 14.3 → 9.6 s
big-10000.canvas 3,995 → 3,232 ms (loaded before the first recording) 10.1 → 5.0 s

(The generated canvases load one image from the web, so it arrives after the first recording; big-10000.canvas's images are beside it.)

Pixels: the develop recording and the layered one, drawn offscreen and compared byte for byte (iOS 27 Simulator, Graphite/Metal), 2,000 and 10,000 nodes, light and dark, full and overview, at scales 0.1, 0.3, 1.33 and 4: 0 bytes differ in all 32 comparisons.

iOS (iPhone 17 Pro Simulator, iOS 27, Release), UI / JS fps, develop → this branch:

pinch pan pan 8× pinch in double-tap
500 59/60 → 58/59 59/60 → 59/60 57/60 → 60/60 60/60 → 58/60 58/60 → 60/60
2,000 53/56 → 56/60 59/60 → 57/59 59/60 → 56/59 59/59 → 59/60 59/60 → 60/60
5,000 53/57 → 57/59 54/59 → 57/59 57/59 → 59/60 57/59 → 59/60 59/59 → 59/59
10,000 55/59 → 57/60 56/60 → 58/60 57/58 → 60/60 59/60 → 59/60 58/60 → 58/60

macOS draws from the same recording code; it was not rebuilt for this PR.

The benchmark

  • Canvases of 500, 2,000, 5,000 and 10,000 nodes (BENCH_SIZES), and optionally big-10000.canvas with its images (BENCH_FIXTURE_DIR): the fixture is the generated 10,000-node canvas with local images.
  • Two phases join pinch, pan and pan at 8×: zooming in from the fitted scale to 4× and back, and a double-tap's zoom to the middle card and back (300 ms ease-out from the JavaScript thread, culling held, as CanvasView's camera animation does).
  • Each canvas waits for the JavaScript thread to be free before measuring (it recorded the Picture meanwhile, which the first phase used to measure instead), and reports how long it was busy.
  • Each phase logs its window on the UI thread's clock ([BENCH-WIN]), so frames on screen can be counted from outside the app.

Checks: npm run typecheck, npm test (216), the example's tsc, and npm run lint (no errors; the 7 warnings develop has).

🤖 Generated with Claude Code

LeslieOA and others added 3 commits November 7, 2026 19:43
…-tap zooms

The benchmark measures canvases of 500 to 10,000 nodes, and optionally
big-10000.canvas with its images (BENCH_FIXTURE_DIR). Two phases join
pinch, pan and pan zoomed in: zooming in from the fitted scale to four
times it and back, and a double-tap's zoom to the middle card and back.
Each phase logs its window on the UI thread's clock, so frames that
reached the screen can be counted outside the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…easuring

A large canvas records its Picture once it opens, holding the JavaScript
thread for seconds at 10,000 nodes, and the first phase measured that.
Each canvas now waits for a second of frames with none over 50 ms, and
reports how long the thread was busy after the fit (busyMs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hen they load

The canvas was recorded twice as it opened, all of it and again without
text for the overview, and both again when its images finished loading.
On a Samsung Galaxy A15 each recording of 10,000 nodes held the
JavaScript thread for 3.5 to 4 s, so a double-tap (a camera animation
driven from that thread) could wait seconds after a canvas opened.

The recording is now one Picture per layer (group cards, group images,
edges and cards, text, file images, group labels), drawn one after
another. The overview is the same layers less text, with nothing
recorded again, and images that finish loading record only the two
layers that draw them. What is drawn, and its order, is unchanged.

A15 (release), JavaScript thread recording at open, before -> after:
2,000 nodes 1.9 s -> 0.7 s; 10,000 nodes 7.9 s -> 3.5 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeslieOA
LeslieOA merged commit 9cf3bae into develop Nov 7, 2026
1 check passed
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