Skip to content

perf: A bunch of render path improvements - #19

Open
Crecket wants to merge 1 commit into
apollyon-sys:mainfrom
Crecket:upstream-pr/render-path
Open

perf: A bunch of render path improvements#19
Crecket wants to merge 1 commit into
apollyon-sys:mainfrom
Crecket:upstream-pr/render-path

Conversation

@Crecket

@Crecket Crecket commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Render path improvements

  • Coalesce redraws into one per frame. draw() is now a requestAnimationFrame scheduler and the old synchronous body is drawNow(), so all ~46 call sites coalesce without being edited. resize() stays synchronous to avoid a blank frame on every ResizeObserver tick.
  • Cache CSS custom properties. renderer.js, grid.js and overlays.js read getComputedStyle(document.documentElement) on every paint; now cssVar() memoises them, invalidated from applyTheme().
  • Decode tiles off the main thread. createImageBitmap() for same-origin tiles, new Image() plus img.decode() for cross-origin ones — fetch is subject to CORS where an <img> load is not. TILE_CACHE becomes a 256-entry LRU that close()s evicted bitmaps instead of growing unbounded.
  • Cap devicePixelRatio at 2 via a shared renderScale(), also used by the contour raster so it cannot disagree with the canvas.
Scenario Painter ms, main Painter ms, branch Per frame, main Per frame, branch
Drag pan, 600 moves 154.1 62.1 1.28 ms 0.52 ms
Wheel zoom, 300 events 126.8 47.5 2.11 ms 0.79 ms
Cold tile pan, zoom 6 141.4 51.8 2.36 ms 0.86 ms
Drag pan at DPR 3 176.1 68.1 1.47 ms 0.57 ms

@apollyon-sys

Copy link
Copy Markdown
Owner

Thanks for the PR - I went through it and the changes look good to me. The render-path optimizations are nicely scoped and I don’t see anything blocking the merge. I’m going to merge this one first since #16 also touches renderer.js / overlays.js

@Crecket

Crecket commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

In my personal version I draw "deadzones" where low arc shots can't reach and height contour lines and more and in that version I've added even more improvements + offloaded some things to webworkers to speed it up even more, so it's at the point where I can maintain 120fps on my macbook. I'll see if I can port some of those over aswell once more of my PRs are merged

@Crecket

Crecket commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

If you want to compare: Open https://wardogs-map.olm.pet, toggle on all layers and then in the devtools run localStorage.setItem('wardogs-fps-meter', '1') and then refresh the page. It should show a FPS counter in the bottom right

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.

2 participants