Pixi v8 VTT perf prototype (THROWAWAY)
Question: can PixiJS v8 (8.22) render a VTT-sized scene smoothly on modest hardware? Measurement tool, not the product.
Run
All commands through devbox (NixOS, nothing global):
devbox run -- npm install
devbox run -- npm run dev # http://localhost:5173
devbox run -- npm run dev -- --host # reachable from LAN
devbox run -- npm run build # tsc + vite build
URL params: ?renderer=webgl|webgpu (force; overlay shows the renderer actually used), ?res=1 (canvas resolution, default min(dpr,2)),
?bench=1 (auto-run benchmark on load), ?benchMs=5000&warmMs=700.
Controls (top right): map size, tile size override (auto = GPU max texture), local map image, grid on/off + cell size, token count, chaos, HP churn, culling, tool (move / pen), +200 random strokes, Run benchmark (markdown table in the textarea; copy button). Mouse: wheel = zoom, drag = pan / drag a token, pen tool: LMB draws, RMB/MMB pans. Touch: 1 finger = drag token / pan / draw, 2 fingers = pinch zoom + pan.
Test on mobile
devbox run -- npm run dev -- --host, open http://<LAN-IP>:5173 on the phone/tablet (same network; open the firewall for 5173 on NixOS if needed:
networking.firewall.allowedTCPPorts). Then use the on-screen overlay and the benchmark button. Not done in this session (no device available).
Headless benchmark (what produced the table below)
bench.mjs drives chromium (from devbox) via playwright-core with SwiftShader (software GL):
devbox run -- npm run build && devbox run -- npx vite preview --port 4173 &
devbox run -- bash -c 'CHROMIUM=$(which chromium) node bench.mjs http://localhost:4173/'
Benchmark (headless Chromium 155, SwiftShader SOFTWARE GL, 1280x720, res 1, WebGL2, maxTex 8192)
CAVEAT: this is CPU-emulated GPU. Absolute numbers are NOT representative of any real GPU. Only the relative shape is informative.
No real-GPU, WebGPU or mobile numbers were collected; run the in-page button on target hardware and replace this table.
fps is capped at 60 (rAF). js ms = JS time per frame measured after Pixi's render call; with software GL the driver blocks inside draw calls so it is inflated at high token counts.
Scenario = view fitted to whole map (so small maps show all tokens on screen, large maps show only a fraction), chaos on, grid on, cull on, 5 s each after warmup.
| map | map path | tokens | strokes | fps | avg ms | p99 ms | worst ms | js ms | frames |
|---|---|---|---|---|---|---|---|---|---|
| 2048 | single | 50 | 0 | 59.8 | 16.7 | 29.9 | 30.3 | 0.9 | 299 |
| 2048 | single | 200 | 0 | 48.4 | 20.6 | 41.2 | 43.1 | 1.7 | 242 |
| 2048 | single | 500 | 0 | 31.0 | 32.3 | 36.3 | 38.0 | 4.2 | 154 |
| 2048 | single | 1000 | 0 | 20.1 | 49.9 | 54.6 | 54.6 | 7.8 | 100 |
| 2048 | single | 2000 | 0 | 11.5 | 86.9 | 94.2 | 94.2 | 85.7 | 59 |
| 4096 | single | 50 | 0 | 60.0 | 16.7 | 27.1 | 33.6 | 0.7 | 300 |
| 4096 | single | 200 | 0 | 56.5 | 17.7 | 33.3 | 34.5 | 1.7 | 282 |
| 4096 | single | 500 | 0 | 43.2 | 23.2 | 49.3 | 51.3 | 3.9 | 216 |
| 4096 | single | 1000 | 0 | 30.1 | 33.2 | 38.0 | 39.2 | 7.0 | 150 |
| 4096 | single | 2000 | 0 | 18.8 | 53.2 | 58.5 | 58.5 | 52.3 | 96 |
| 8192 | single | 50 | 0 | 60.1 | 16.6 | 26.1 | 29.3 | 0.7 | 300 |
| 8192 | single | 200 | 0 | 58.4 | 17.1 | 32.9 | 40.8 | 1.7 | 291 |
| 8192 | single | 500 | 0 | 48.0 | 20.8 | 40.2 | 41.0 | 3.9 | 240 |
| 8192 | single | 1000 | 0 | 36.4 | 27.5 | 33.2 | 39.8 | 7.3 | 182 |
| 8192 | single | 2000 | 0 | 23.4 | 42.8 | 48.5 | 49.1 | 42.2 | 118 |
| 16384 | 4 tiles | 50 | 0 | 59.7 | 16.8 | 28.0 | 33.0 | 0.7 | 298 |
| 16384 | 4 tiles | 200 | 0 | 58.1 | 17.2 | 32.2 | 34.2 | 2.2 | 290 |
| 16384 | 4 tiles | 500 | 0 | 48.1 | 20.8 | 38.3 | 40.6 | 4.8 | 240 |
| 16384 | 4 tiles | 1000 | 0 | 37.8 | 26.5 | 44.9 | 52.2 | 8.2 | 189 |
| 16384 | 4 tiles | 2000 | 0 | 25.4 | 39.3 | 45.4 | 46.0 | 38.7 | 129 |
| 4096 | single | 50 | 200 | 38.2 | 26.1 | 49.1 | 49.7 | 0.7 | 191 |
| 4096 | single | 500 | 200 | 28.2 | 35.4 | 45.5 | 111.9 | 4.7 | 141 |
Techniques used (v8)
- Map larger than max texture: max texture read from the backend (
gl.getParameter(MAX_TEXTURE_SIZE)/device.limits.maxTextureDimension2D); if map > that (or > the "tile size" override) it is sliced into square tiles, each its own canvas ->Texture.from(canvas)->Spriteat an integer position. Overlay says SINGLE vs TILED. Here 16384 on a maxTex 8192 device = 2x2 tiles of 8192. - Culling: manual
Culler.shared.cull(world, screen, false)each frame (not the plugin, so it can be toggled); map tiles and stroke sprites arecullablewith bounds; tokens use a fixedcullArearectangle (no per-frame bounds calc) andcullableChildren = false. - Token labels under HP churn:
BitmapTextwith a pre-installedBitmapFont(BitmapFont.install), notText: changing.textonly rebuilds quads, no canvas raster or GPU upload. Circle bodies: one sharedGraphicsContextper colour (6), tessellated once, reused by all tokens. Tokens are pooled (removed/added, never destroyed). - Grid: one
TilingSpriteover a small cell texture (1 quad regardless of map size) rather than thousands ofGraphicslines. - Stroke baking: live stroke =
Graphicschunks of <=48 points (only the last chunk is re-tessellated per move, older chunks frozen). On pointer up the chunks are rendered once withrenderer.textureGenerator.generateTexture({target, frame, resolution, antialias})into aSpriteand the Graphics are destroyed. Bake resolution follows zoom (1..2), capped so no side exceeds 4096 px. - Input: DOM pointer events on the canvas with a hand-rolled pan/zoom/pinch (pixi-viewport 6.0.3 declares
pixi.js >=8peer, but token drag + pen + pinch needed custom handling anyway). Pixi's federated event features are disabled; token hit test is an O(N) scan on press only.
Findings
Measured (software GL only):
- Token count dominates. With a 4096 map at fit zoom: 50 tokens 60 fps, 500 ~43 fps, 2000 ~19 fps. On SwiftShader that is largely fill/raster of BitmapText glyph quads and circle geometry, so it says little about real GPUs.
- Map size alone barely matters (2048 vs 16384 comparable at equal on-screen token count); the 2048 rows are slower only because all tokens are on screen at once while larger maps cull most of them. So culling works and tiling (2x2) cost no visible fps.
- Worst-frame spikes of ~30-50 ms show up at 99th percentile even at 50 tokens (likely software rasteriser/GC; unverified).
- 200 baked strokes did cost FPS here (4096/50 tokens: 60 -> 38 fps; 4096/500: ~43 -> 28 fps). It does not meet the "no noticeable drop" criterion on this renderer. JS time per frame did not change, and a draw-call counter showed only ~4-7 draws/frame with strokes present, so it is not batching/CPU; hiding the stroke layer restored 60 fps. Hypothesis (NOT verified): SwiftShader sampling of 200 distinct, large (e.g. 380x550) un-mipmapped textures minified at zoom 0.16 is slow in software, and a real GPU would not show it. Candidate fixes to try on real hardware if it reproduces: bake into shared atlas / merge strokes into per-region tiles, mipmaps on stroke textures, or smaller bake resolution when zoomed out.
- Live drawing of a 400-point stroke (checked with scripted mouse, visual only, no timing) rendered and baked to a correctly-aligned sprite.
Not measured / hypotheses:
- Everything on real GPUs, WebGPU (
?renderer=webgpuuntested), mobile/tablet, touch/pinch behaviour, HP churn and the Run-benchmark under churn (benchmark runs churn OFF; toggle is manual). - Chaos at 2000 tokens costs per-frame
position.seton 2000 containers: hypothesis that it is cheap on CPU; thejs mscolumn is inflated by software GL blocking so it can't confirm.
Worries for a real VTT:
- BitmapText atlas is rasterised at one font size: labels go blurry when zoomed in (needs MSDF or a zoom-dependent font), and the installed glyph set is Latin/digits only; non-Latin names need
Text/HTMLText or a bigger atlas. - 16384 px maps on a device with maxTex 16384 take the single-texture path = ~1 GB of GPU memory; on mobile (maxTex often 4096-8192, small VRAM) tiling is required and memory, not fps, is the limit. Use the tile-size override to force tiling and check memory on a device. Tile seams at fractional zoom were not inspected.
- Per-stroke textures: 200 strokes = 200 separate GPU textures (see above); a real session with thousands of strokes needs atlasing/merging and texture GC planning. Very long single strokes are baked at reduced resolution (4096 cap) and will look soft.
- Tokens are one Container + 2 children each; 2000 tokens = 6000 scene nodes touched per frame in chaos mode.