Skip to content

Performance

Numbers measured here, in your browser, on this machine. Load a synthetic document and draw over it: the canvas keeps responding because a redraw only touches the visible region, and drawing only redraws the overlay. Every figure below is produced by running the real engine, not quoted from a specification.

Empty drawing canvas.
Drawing on a loaded document stays smooth because the live stroke is rendered on a separate overlay canvas: the thousands of committed strokes are not touched until the pen lifts. Pointer input is batched once per animation frame and never triggers a Blazor render. The status line says whether this page took the zero-copy render path, which WebAssembly does.

What is being timed

The document is built in one batch, so it raises a single change and the canvas redraws once. A redraw is a recording of canvas commands; with ClipBounds set to the visible rectangle it records only the elements whose bounds intersect it, which is what a pan or a committed stroke really costs. Moving every stroke is one frame of dragging a selection of the whole page: each element gets a new transform and its points are never touched, and undoing it puts the exact transforms back. The two SVG exports write the same file, once as a string and once straight to a stream.

using (_document.BeginBatch("Generate"))
{
    for (int i = 0; i < _strokeCount; i++) _document.AddElement(CreateStroke(random), layer);
}

var culled = new BinkCanvasRenderContext(1 << 16);
BinkDocumentRenderer.Render(_document, culled, new BinkRenderOptions { ClipBounds = visible });

_document.ReplaceElements(_document.AllElements.Select(e => e.Translate(new Vector2(12f, 0f))), "Move");
BinkSvgExporter.Export(_document, stream);   // for a large drawing: no string the size of the file

Why it stays fast

  • Two canvases. Committed elements live on a document canvas, the live stroke and tool previews on an overlay; drawing redraws only the overlay.
  • Input never re-renders Blazor. Samples arrive once per animation frame and go straight to the tool; processing a frame of 64 samples allocates nothing.
  • Geometry is cached per stroke and brush, and an element's bounds never build its outline, so loading a document does not build every outline up front.
  • Paths are sent once. The browser keeps every path it has drawn, and a redraw names it by a slot: about eight numbers an element instead of every coordinate, which is what keeps Blazor Server fast too.
  • Edits are transforms. Moving, resizing and rotating change a matrix per element, and a long drag is folded into one replacement per element in history.
  • Element lookup is constant time, each layer indexing its elements by id, so dragging thousands of selected strokes stays interactive.

To keep a very large document responsive: keep the view meaningful (culling is what makes ten thousand strokes interactive; a zoomed-out view of everything is the expensive case by definition), add many elements in one BeginBatch, export large SVG to a stream, and raise BinkDocumentLimits deliberately rather than by default.

An unhandled error has occurred. Reload 🗙