What takes the time
Reading a message is several jobs, and a program pays for each one separately.
- Finding things. Where does this field start, where does the record end, where is the 1,500th entry?
- Converting. The characters
1,9,4,2have to become a number. Text may have to be unescaped, and checked to be valid. - Making objects. Most programs do not want bytes. They want a record, a list, a string of their own language, and each of those is memory that has to be asked for and later given back.
- Copying. From the network into a buffer, from the buffer into the objects.
- Checking. Bytes from a stranger may be wrong on purpose. Something has to make sure a length does not point outside the message.
Writing is the same list backwards. In nearly every measurement, making objects is the largest part and converting the second. So the fastest code is mostly the code that manages not to do one of these jobs at all.
The first source: structure
The format decides which of those jobs can be left out. This is decided when the format is designed, and no later cleverness changes it.
- A length in front lets a reader step over. Text formats mark the end of a thing with a character, so the only way to find the end is to look at everything before it. To reach the last field of a JSON document, every character of the document has to be examined.
- A table lets a reader jump. A regular node (chapter 7) points to a table of where its fields are. Reading one field is two steps, however many fields there are.
- Numbers that are already numbers need no converting. Four bytes in the processor's own order are read with one instruction (chapter 2).
- Data that can be used where it lies needs no objects. A Dagr reader can hand out a small view that points into the buffer. Nothing is copied, and nothing is allocated, until the program asks for a value.
- Checks done at each read need no pass over everything. A reader that tests every position as it uses it never has to verify a part of the message it does not look at.
Structure also sets limits in the other direction, and Dagr has chosen some of them. A packed node (chapter 6) is small because it has no table, so reaching its tenth field means stepping over nine. Numbers of variable length are smaller and take a little longer to read than fixed ones. A format that is simply the program's memory written to disk reads faster than Dagr, and gives up size, portability and the freedom to change. Every one of these is a trade, and the right one depends on what the data is for.
The second source: engineering
Within what the structure allows, an implementation can still be several times faster or slower than another. JSON is the best example. Its structure is against it on every point above, and decades of work have made its parsers remarkably fast anyway: they examine many characters at once with special processor instructions, avoid branches, and convert numbers with carefully proved shortcuts. Such a parser gets through a gigabyte of text in about a second.
What engineering cannot do is leave the structure. The best JSON parser in the world still has to look at every character to find the last field.
It also works the other way round: a good structure can be wasted. Two examples from Dagr's own history, in Go, with not one byte of the format changed:
- A loop that was slower than it looked. Dagr's Go reader offered "give me entry number i" on a packed list. A packed list has no table, so that call stepped through the list from its start, every time. A loop over all entries did the work of the whole list for each entry. Measured against Protocol Buffers on telemetry data, it was one and a half times slower. After the reader was given a way to walk the list once, the same task was about nine times faster.
- A writer that was slow for reasons that had nothing to do with writing. Encoding the same telemetry was at first five times slower than Protocol Buffers. Profiling showed that the encoding itself was not the cost. The cost was how values were passed from function to function, and memory allocated along the way. With that changed, the encoder itself was level with Protocol Buffers.
So a benchmark measures a format and an implementation together, and it cannot tell you which of the two you are looking at. A slow result may mean a slow format or code nobody has profiled yet. A fast one may mean a fast format or ten years of tuning.
The third source: the language
The same design, engineered with the same care, does not run equally fast everywhere. In C++, Rust, Go or Swift, the code a generator writes is compiled to machine instructions, and a view into a buffer costs almost nothing. In two very widely used languages it is different.
JavaScript and TypeScript
JSON.parse and JSON.stringify are not written in JavaScript. They are part of the engine, written in C++ by the people who wrote the engine, and they can do things no JavaScript program can: create objects in one step, skip the checks that ordinary code passes through, and use the processor instructions mentioned above. A reader for any other format, Dagr's included, is ordinary JavaScript. However good its structure, it starts behind when the task is "turn the whole message into objects".
The obvious answer is to write the reader in a compiled language too and call it from JavaScript. That is not always possible, and it helps less than one would hope. A web page cannot load a native library at all. It can load WebAssembly, but every string and object still has to be carried across the border between the two worlds, and that crossing costs about what was saved. A server can load a native module, at the price of building it for every platform.
What remains is the structure. A JavaScript reader that does not turn the whole message into objects can win, because the built-in parser has no way of doing less than everything.
The panel below measures this on your device. It makes a list of people, writes it as JSON and as Dagr, and then does four tasks both ways. The Dagr side is the TypeScript that Dagr generates, unchanged.
The numbers differ from one device and browser to the next. On the machines this was tried on, the pattern was the same:
- Whole-message work goes to JSON. Using every field of every person, and writing everyone, are what the built-in code is best at. Dagr's TypeScript is behind, clearly so when writing.
- Partial work over everyone is about level. To add up the ages, the JSON side still parses every name. Dagr's reader does not, but it makes a small reader object for each person, in JavaScript, and that costs about what the names did.
- One value out of many goes to Dagr, by a factor in the hundreds or thousands. A list in a regular node is a table of positions, so person number 1,501 is a multiplication and two small reads away. The factor grows with the list, because one side's work grows and the other's does not.
The third bar of that first task shows the same read done a slower way: ask for the whole list, which makes a reader object for every person, and then take one. Until this chapter was written, that was the only way Dagr's TypeScript offered. Measuring for this page showed that a read the format makes almost free cost as much as parsing the JSON. The generator was given a way to read one entry directly, and the bar next to it is the result. Not one byte of the format changed. That is the difference between the first two sources of speed: the structure allowed the fast read all along, and it took engineering to deliver it. From the JSON side, no amount of engineering can do the same, because the text has no table to look in.
Python
Python runs its programs through an interpreter, which is tens of times slower than compiled code at work like this: looking at bytes one by one, shifting bits, following offsets. Python's fast libraries are fast because they are not Python. Its json module is written in C, and so are the popular Protocol Buffers and JSON packages.
Dagr's Python target is pure Python, and it is the slowest thing in this chapter. That is partly the interpreter and partly a decision: it is Dagr's reference implementation. It does not generate code for a schema. It reads the schema while it runs and decides, field by field, what to do, and it always turns the whole buffer into objects. That makes it short, easy to check against the specification, and the writer that all the other languages are tested against (chapter 19). It was written to be right, and nothing in it was written to be fast.
The way to get the speed back is the way every fast Python library takes: do the work in compiled code, and let Python call it. For Dagr that means the generated Rust behind a thin Python layer. In the signed-token project below, the pure Python version checks a token several times more slowly than the usual Python JWT library. The same token checked through Rust is nearly three times faster than that library. Dagr can also generate such a library itself, for reading graphs and sinks into the column tables that Python's data tools work on. A general Python interface over generated Rust, for any schema, does not exist yet.
Where Dagr stands
Below are six sets of measurements. Two are Dagr's own benchmark, in Rust and in C++ and Java. Three come from projects that put Dagr to work on something real, and one is run by somebody else. Each bar is a factor: how many times faster or smaller Dagr was than the thing it was compared with, or how many times slower or larger.
Six sets of numbers from different machines cannot be added up, but they agree with each other on the following.
- Reading in place is where Dagr is far ahead. When a program keeps the buffer and reads what it needs, Dagr is ahead of formats that must be decoded first by a factor between a few and nearly a hundred, in every compiled language measured. This is structure: the work that was left out was most of the work.
- Turning everything into objects is not. When every value is copied out into the program's own records, Dagr is somewhere between a little behind and a little ahead of Protocol Buffers, depending on the language. A program that receives Dagr and immediately converts it to its own structures has gained nothing, and in some cases has lost. The telemetry project found exactly this: the standard collector passes its own structures between its parts, so inside it the fast reads cannot happen.
- Writing is about level. With the direct builder, which writes the plain values of chapter 4 with no arena behind them, Dagr is somewhat ahead of Protocol Buffers in Rust and C++. In Java it is level for whole messages and clearly behind for a stream of small records. It is behind in Go when the data starts out as Protocol Buffers' own structures. Through the arena, which exists so that a graph can be changed, it is behind.
- Against JSON it is ahead on everything in the compiled languages. Several times faster to write, ten or more times faster to read, and about half the size before compression. In JavaScript the built-in JSON wins the whole-message tasks, as you measured, and in pure Python it wins everything but size.
- The formats that are memory written down read faster. FlatBuffers and rkyv, read without checking, are several times to tens of times faster than Dagr at fetching a field, because there is nothing to decode at all. They are larger, and when the bytes are not trusted they need a checking pass first that costs more than Dagr's whole read.
- Size is level with Protocol Buffers, within a few percent either way, and after compression nearly everything is level with everything (chapter 17).
- Pure Python is slow, by a factor of several against Python's C-backed libraries and more against the fastest.
- The format is often not the largest cost. In the token, most of the time to check one is the cryptography. In the social network protocol, the signature is three quarters of a write, and no encoding changes that. Where a compressor was running on every message, removing the need for it saved more than any difference between formats.
Reading these numbers
- Most of them were measured by Dagr's author. The projects are public and can be run again, and they report their losses, but they are not independent. The exception is the last set: that benchmark belongs to someone else, who ran it on his own machine. Its Dagr entries were contributed by Dagr's author and accepted there.
- That independent benchmark measures only the task Dagr is weakest at. Every serializer in it has to turn the whole message into objects, so reading in place is never measured. It is a fair test of everything else.
- A factor holds for one machine, one data set and one pair of libraries. The same comparison on a processor's slow cores, or on messages of a different shape, gave different factors. The bars show the range that was reported, and the direction is more reliable than the size.
- Libraries are compared, not formats. One JWT library was forty times slower than Dagr for reasons that had nothing to do with JSON. That row is left out here.
What follows from this
- Choose Dagr for speed when the reader can keep the buffer: a file that is mapped into memory, a message from which a router needs two fields, a log that is searched, a cache, a token that is checked on every request.
- Do not expect speed from it when everything is converted on arrival, or when the program is JavaScript in a browser and wants ordinary objects. The reasons to use it there are size, a schema, and the things earlier chapters were about.
- In Python, use it through compiled code, or accept the reference implementation's speed for tools and tests.
- Measure your own case. Every surprise in this chapter, in both directions, was found by measuring something that had been assumed.
What these panels are.
- The first panel runs in your browser, on your device, when you press the button. The Dagr side is the TypeScript that
dagr buildgenerates for a small schema, with Dagr's TypeScript runtime, bundled into one script and otherwise unchanged. The bytes it writes are checked against Dagr's reference writer: identical. Both sides are checked to compute the same answer for every task. - A browser's clock is deliberately coarse, so each task is repeated until it has run for a while and the best of several rounds is shown. Small differences mean nothing. The JSON side starts from text that is already in memory.
- "Dagr, building the whole list first" uses the same generated code in the way that was the only one until late 2026: the list's getter, then one entry of the result.
- The second panel measures nothing. Its factors are copied by hand from the published results of the projects named in it, rounded, and each set links to its source. Where a source gives a range, the bar is drawn at the middle of it. The factors for the independent benchmark were computed from the data behind its dashboard, as the average over its five standard data sets with one record per message.
Try it
- Measure with 200 people and with 20,000. Which bars grow a hundredfold, and which one hardly moves? What does that say about the work each does?
- Adding up the ages is about level, and reading one age is not. What would Dagr's TypeScript have to stop doing for the first to look more like the second?
- In the "add up everyone's age" task the JSON side reads every name. Is there any way to write that task, using
JSON.parse, that does not? - If you have a second browser, measure there too. Which results change most, and are they the JSON ones or the Dagr ones? Why might that be?
- In the second panel, find a task where Dagr is ahead in one language and behind in another. Which of the three sources explains it?
- In the telemetry set, reading one span out of 500 is much further ahead than visiting all of them. What has the reader not done in the first case that a decoder always does?
- A service receives a message, changes one field and sends it on. Which of the measurements here tells you most about how Dagr would do, and which tells you least?
What comes next
The guide has now described the whole format and how it performs. Two chapters remain. Chapter 19 is about how Dagr was built: specifications first, tests that compare bytes, and an AI doing most of the typing. Several of the measurements in this chapter were made the same way.
