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.

  1. Compared with C and Go
  2. The whole table
  3. One record at a time
  4. Reading the numbers

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:

OperationNihilCGo
write the table (atomic, synced)381 ms535 ms421 ms
read the whole table201 ms112 ms110 ms
where(active && price < 200.0)8.4 ms5.1 ms5.9 ms
sum(price * .qty)5.6 ms4.0 ms3.2 ms
sort(-price)215 ms208 ms762 ms
build the key index128 ms93 ms83 ms
find by key (each)2.2 µs1.1 µs1.2 µs
change by key (each, 1 fsync)0.15 ms0.07 ms0.07 ms
peak memory384 MB187 MB329 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.

OperationLinux, 100 000Linux, 1 000 000macOS, 1 000 000
make the records in memory19 ms211 ms109 ms
write the table: @>> path, rows (atomic, synced)35 ms382 ms322 ms
read the whole table: ITEM @ path17 ms199 ms79 ms
where(active && price < 200.0)0.7 ms8.2 ms6.3 ms
count(category == 7)0.3 ms5.2 ms1.2 ms
sum(price * .qty)0.4 ms5.4 ms3.4 ms
sort(-price)16 ms210 ms163 ms
the first key operation (reads the table and builds the index)17 ms112 ms69 ms
size of the table / of its index4.8 MB / 1 MB48 MB / 8 MB48 MB / 8 MB
peak memory of the whole run59 MB384 MB388 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:

OperationLinuxmacOS
read record i: ITEM @[i] path0.9 µs1.6 µs
find by key: ITEM @{k} path2.0 µs2.2 µs
change by key: find it, then @{}>> path, r (1 fsync)0.16 ms4.7 ms
add by key: @{}>> path, r with a new key (2 fsyncs)0.30 ms9.2 ms
delete by key: ITEM @{k} path = _ (2 fsyncs)0.31 ms9.6 ms

Reading the numbers

The numbers come from the runs of 23 November 2026, with Nihil 4.4.0. The rules behind them are in SPEC §20.