Structurae 1.0: Graphs, Strings, and WebAssembly

Maga D. Zandaqo
Jun 8 · 4 min read
Tabula Peutingeriana, 13th century. Make Graphs This Great Again!

Notes on Binary in JavaScript

Although dealing with binary was not the focus of structurae, it had to go “low” in its quest for efficiency. Under the hood, structurae makes heavy use of TypedArrays and bitwise operators to act on byte and bit level. This is not as common as one would expect, so let us reiterate a few basics of dealing with binary in JavaScript.

Memory Efficient Graphs

JavaScript libraries implementing graphs seem to focus on either graph visualizations or serving as learning material for students. In both cases, the performance impact gets overlooked and the implementations are woefully inefficient when it comes to dealing with large graphs. For example, some implementations opt for representing each edge with a JavaScript object which is 40–104 bytes², whereas for unweighted graphs a single bit would do. The exorbitance of it really shows once we start dealing with hundreds of thousands of nodes and edges.

The Joy of C-like Strings

With Edge adopting Chromium, all modern browsers now support the Encoding API. The API essentially lets us convert JavaScript strings to a byte stream and back. We had libraries doing it before, but this API brings built-in support and, more importantly, establishes a common standard for representing strings in binary: it uses Uint8Array and encodes into UTF8.

WebAssembly Integration

The premise of structurae is getting JavaScript code reliably fast without resorting to micro-optimizations or rewriting it to target WebAssembly. That said, there are cases where we can benefit from offloading certain tasks to WebAssembly.


The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.

Maga D. Zandaqo

Written by

The Startup

Medium's largest active publication, followed by +469K people. Follow to join our community.