Performance of tables
How long Nihil's tables (Learn §9, §13) take to write, read, query and change, measured by bench/tables.nihil, and how that compares with the same work written in C and in Go. The records are synthetic, made from a fixed pseudo-random sequence so every run has the same data, and each one has six fields in 50 bytes:
ITEM = @[#code: INT(8); name: STRING(20); category: INT(4); price: FLOAT(10); qty: INT(6); active: BOOL];
The machines: Linux, a GitHub Actions runner (Intel Xeon 6975P-C, 4 CPUs, Ubuntu 24.04), where Nihil, C and Go all run
natively; and macOS, an Apple M4, where Nihil's x86-64 code is translated to ARM64. To measure your own machine, run
bench/run.sh or, for the comparison, bench/compare/run.sh in the repository.
Compared with C and Go
bench/compare holds the same program in C (cc -O2)
and in Go: the same records, the same text table, the same hash index on disk and the same number of disk syncs. Run with
KEEP=1, the three leave byte-for-byte the same table after every change, addition and deletion. Linux, all three native,
1 000 000 records:
| Operation | Nihil | C | Go |
|---|---|---|---|
| write the table (atomic, synced) | 381 ms | 535 ms | 421 ms |
| read the whole table | 201 ms | 112 ms | 110 ms |
where(active && price < 200.0) | 8.4 ms | 5.1 ms | 5.9 ms |
sum(price * .qty) | 5.6 ms | 4.0 ms | 3.2 ms |
sort(-price) | 215 ms | 208 ms | 762 ms |
| build the key index | 128 ms | 93 ms | 83 ms |
| find by key (each) | 2.2 µs | 1.1 µs | 1.2 µs |
| change by key (each, 1 fsync) | 0.15 ms | 0.07 ms | 0.07 ms |
| peak memory | 384 MB | 187 MB | 329 MB |
Nihil writes the table faster than C and Go, sorts as fast as C, and is within about twice their time on the rest. The C and
Go programs keep their two files open and trust that nobody else changes them; Nihil checks the table at the path on every
operation (one stat), so it still sees what another program or an editor did to it.
The whole table
Writing, reading and querying grow with the table. The queries are compiled into loops where they are called.
| Operation | Linux, 100 000 | Linux, 1 000 000 | macOS, 1 000 000 |
|---|---|---|---|
| make the records in memory | 19 ms | 211 ms | 109 ms |
write the table: @>> path, rows (atomic, synced) | 35 ms | 382 ms | 322 ms |
read the whole table: ITEM @ path | 17 ms | 199 ms | 79 ms |
where(active && price < 200.0) | 0.7 ms | 8.2 ms | 6.3 ms |
count(category == 7) | 0.3 ms | 5.2 ms | 1.2 ms |
sum(price * .qty) | 0.4 ms | 5.4 ms | 3.4 ms |
sort(-price) | 16 ms | 210 ms | 163 ms |
| the first key operation (reads the table and builds the index) | 17 ms | 112 ms | 69 ms |
| size of the table / of its index | 4.8 MB / 1 MB | 48 MB / 8 MB | 48 MB / 8 MB |
| peak memory of the whole run | 59 MB | 384 MB | 388 MB |
One record at a time
A record's place comes from its number (fixed width) or from the index on disk, so the rest of the table is never read. 100 000 records:
| Operation | Linux | macOS |
|---|---|---|
read record i: ITEM @[i] path | 0.9 µs | 1.6 µs |
find by key: ITEM @{k} path | 2.0 µs | 2.2 µs |
change by key: find it, then @{}>> path, r (1 fsync) | 0.16 ms | 4.7 ms |
add by key: @{}>> path, r with a new key (2 fsyncs) | 0.30 ms | 9.2 ms |
delete by key: ITEM @{k} path = _ (2 fsyncs) | 0.31 ms | 9.6 ms |
Reading the numbers
- A write by key waits for the disk. A change in place syncs the table; an addition or a deletion syncs the table and
the index, so that a crash never leaves them out of step. That is almost all of its time, and the disk decides it (tenths of a
millisecond on the Linux runner, 5 to 9 ms on the Mac's SSD, where the sync goes through the drive's cache). To change thousands
of records at once, change them in memory and write the table once with
@>>: a million records take under half a second. - Reading by key or by number is cheap at any size: the runtime keeps the files open between reads, and a lookup by key is
one
statof the table and two reads, about 1 µs and 2 µs at a hundred thousand records or a million. - A garbage collection stops the program while it goes over everything in memory (SPEC §12.4). With a million records the program holds about 380 MB, and one collection takes 70 to 150 ms, depending on the machine: timed 1 000 at a time, 19 of the 20 laps of reads take 1 to 2.5 ms and one takes about 150 ms (Linux, an i7-1255U). Spread over the 20 000 operations, that one pause made reading record i measure 7 to 9 µs, where it typically takes 1 µs. The benchmark prints the median lap and the slowest after each measurement of one record at a time, and the comparison shows both where they differ. A program that keeps hundreds of MB of values pays such a pause now and then (a batch job hardly notices; a server answering requests sees it as an occasional slow answer); C has no collector, and Go's runs alongside the program, with pauses under a millisecond.
- In memory a record is bigger than on disk: each field takes an 8-byte slot, and a text its own bytes besides. This run holds two copies of the records (the ones it made and the ones it read). Reading a table needs, at its peak, two to three times the file's size.
- One writer at a time. A table is a file, not a server: two programs writing the same table at the same moment are not coordinated.
- On the Mac, Nihil's code is translated from x86-64 to ARM64, which costs most on small, frequent operations.
- GitHub's runners are not all the same machine, and a shared server under load gives noisier numbers still. Compare numbers from the same run.
- The clock is
std:time'snow_us(), in microseconds. The operations on one record are timed thousands at a time (20 000 reads, 300 writes) and divided; the reads are also timed 1 000 at a time, for the median.
The numbers come from the runs of 23 November 2026, with Nihil 4.4.0. The rules behind them are in SPEC §20.