Skip to content
Maksym Skorina
← All notes
4 min read

1.08x to C, and the cases that still lose

The geometric mean is a useful summary and a bad victory lap. What the 17-case KshanexLang benchmark set actually says.

benchmarks · LLVM · performance

The headline number is easy to quote: across 17 benchmarks, KshanexLang is 1.08x C at -O2 by geometric mean. It is also the least interesting part of the result.

A geometric mean compresses a distribution into one number. It hides the shape: which cases win, which lose, and whether the gap comes from the language, the runtime, or the build. The benchmark table keeps the shape visible. This note is about the parts that do not fit the headline.

The wins are not accidents

hashmap runs at 0.38x C — 45.88 ms against 120.80 ms. matmul_transpose runs at 0.45x C, 90.96 ms against 202.64 ms, and 2.2–2.7x faster than the C, Rust, Zig, Go, and Swift twins. That case is built on stdlib/tensor.knx: transpose B once, then dot each row of A against each row of Bᵀ with a contiguous 4 x double load and a horizontal add. Every other twin walks B in column order and misses cache on every element.

fib_rec (0.95x), net_echo (0.97x), float_sqrt (0.98x), prime_sieve (1.01x), and vec_sum (1.04x) land at or near parity. net_echo moves 20,000 messages of 64 bytes over loopback TCP with one receiver and one sender; the KshanexLang twin allocates a string per recv, the C twin does not, and the case still reads 365.60 ms against 377.22 ms. There is no buffer to fill, no event loop to wake, and no background runtime thread between the call and the syscall.

The losses are specific

match_dispatch is the worst case at 2.43x. It is also the one that moves on its own: 107 ms, then 127 ms, then 97 ms across runs, while the disassembly of the hot loop and its eight case bodies is identical byte for byte, addresses aside. A 100M-iteration loop is that sensitive to where it lands in .text. The number is written down rather than smoothed over.

json_parse is 1.91x. It used to be 3.81x, and the gap measured two representation choices rather than the optimiser. A string was a C string, so char_at re-ran strlen on every access — quadratic in the document. A string block is [rc][len][bytes] now and the handle still points at the bytes, so the C ABI is unchanged and char_at is a load and an add. The document’s own construction was the other half: int_to_str was snprintf("%lld"), thirteen variadic, locale-aware calls and thirteen allocations per document. It is a divide-by-ten loop into the destination buffer now. 729 ms → 485 ms → 364 ms.

alloc_churn is 1.72x. The runtime keeps free lists for four block sizes and stores the size class in the top bits of the refcount, so a release knows where to return the block. A thread-free module pulls and pushes from those lists; a module with threads compiles the flag to zero and goes to malloc/free. The remaining distance to C is the release barrier and the vector’s buffer, not the allocator. The barrier stays: without it, LLVM can prove whole malloc/free pairs unobservable and delete them, which takes the case from 1.0 s to 34 ms with an unchanged checksum. That is a true result for the program and a false one for a case whose description is “allocate, read back, free”.

sort_int is 1.70x, and the gap is the bounds check. With get_unchecked the same program runs at 1.03x C. The tables measure the checked default, because that is the language’s contract; an opt-out is not a design.

What changes next

The next wins are dataflow, not flags. sort_int and matmul_f64 need the check hoisted out of a loop whose index is provably in range. match_dispatch needs a layout that is less sensitive to where the loop lands. alloc_churn needs the allocator and the release path, not a compiler switch. json_parse is already a different program than it was a few months ago.

If a benchmark cannot be reproduced, it is not a benchmark. The table is generated, not hand-edited:

kshanex bench --markdown > docs/BENCHMARKS.md

The geometric mean is 1.08x. The distribution is the story.

—views4 min read

Comments

Loading…
0/1200

No comments yet. Add the first note.