← Back to context

Comment by agys

9 hours ago

A couple of years ago I wrote extensive benchmarks on three browser-based rendering techniques: text in the DOM, 2D canvas, and WebGL canvas. The DOM approach is the purest, as it uses a font, and it can achieve very good performance. The only noticeable slowdown at 60 FPS occurs when the character color changes frequently within each line: each new character needs to be wrapped in a span. 2D canvas is a bit more flexible but not necessarily faster. WebGL is obviously the fastest, at 1000+ FPS, and pixel fonts can be rendered ultra-crisp as well.

Below is the DOM test for frequent vertical color changes. Press and hold the cursor over the ASCII output to change the orientation (notice the FPS drop at the top left).

https://play.ertdfgcvb.xyz/#/src/basics/performance_test

I suspect DOM is probably fast enough for most usecases. For me, DOM only started chugging because every tile (2 half-width characters in hexwalker) was a react element and those would get garbage collected en-masse and cause studder.