Menu

1 / 3

500,000 Shapes on a 2D Canvas: What Helped, and What Made It Slower

DEV Community: frontend·kulman Lab·10 days ago
#TMPv6Zos
#devtofrontend#devto#dev#objects#drawing
Long article (1082 words) — no AI summary yet.
Reading 0:00
15s threshold

I build KulmanLab CAD, a free 2D CAD that runs in the browser. It has no backend, it opens DXF files, and everything is drawn with plain Canvas 2D.

CAD files are a good stress test: hundreds of thousands of lines, arcs, text labels and hatches, and a user who expects panning and zooming to stay smooth.

Here is what I learned, written as problems and fixes you can reuse in any canvas app: a map, a diagram editor, a node graph or a chart.

The timings are my own measurements, mostly in a headless browser. Compare the before and after, and don't treat them as universal numbers.

Problem: working out "is it visible?" was the slow part

Everyone's first optimization is to skip off-screen objects. It works, but you need each object's bounding box to do it.

For lines that's nothing. For text you have to measure it on the canvas. On 100,000 objects, getting the bounds cost about 70 ms per frame.

Fix: cache them.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.