Skip to content
Tech News
← Back to articles

We rewrote our custom visualisation renderers from SVG to be in Canvas

read original more articles
Why This Matters

Rewriting the custom visualization renderers from SVG to Canvas significantly enhances performance by reducing the browser's workload, enabling faster rendering and interaction with large profiling datasets. This shift demonstrates how leveraging Canvas can overcome the limitations of DOM-heavy SVG graphics, leading to more responsive tools for developers and improved user experience. Such innovations are crucial for advancing data visualization efficiency in the tech industry.

Key Takeaways

We've been working hard at a revamp of our profiling dashboard and we wanted to share some of our learnings and improvements we've observed along the way, backed by numbers.

This is not the first time we have written about making flame graphs fast. Last year we parallelised the SVG render and took the initial render of a large query from around eight seconds to about 91 milliseconds.

But SVG has a ceiling, and that ceiling is made up of DOM nodes. Every frame in a flame graph is a <rect> and a <text> . Therefore a large profile is tens of thousands of frames, which is tens of thousands of DOM nodes and for each node the browser has to style, lay out, paint and keep in a tree it can later garbage collect. To stop that from freezing the tab, the old renderer drew nodes in batches of roughly 500 per frame. This worked, but batching the DOM is only just treating a symptom. The fundamental problem here was that we were asking the browser to manage an enormous amount of structure.

To be honest, we more or less said it at the end of that post: we suspected the next real gain was to stop using the DOM for the flame graph, even though we were unsure as to how much Canvas would actually buy us. This post is us answering our own open question.

tl:dr Why is the new profiler dashboard faster?

The old renderer was drawn with SVG, one DOM element and a small JavaScript object for every one of its tens of thousands of frames, all of which the browser then had to style, lay out, paint, and garbage-collect.

The new one draws the same data on a Canvas: it reads the numbers straight from their columns and paints pixels, with no per-frame element or object at all. This makes zooming, resetting, and scrolling feel instant, because none of them touch the DOM any more.

A flame graph is made up of frames

Let's go through the differences between the SVG and Canvas HTML elements with respect to rendering flame graphs.

The SVG and the DOM are retained-mode APIs in the browser while the Canvas is an immediate-mode API. What does this mean?

... continue reading