Charge the scoreboard for -L and the other fastwc

-L is now the widest gap in the table rather than the one case we lost,
so the README stops pretending that "never slower" covered it and says
where the numbers came from. The Rust clone that held the record gets
its own section: what it did right, what it still wins (dense CJK, by
carrying a width table where we call wcwidth), and what it lost.

PERFORMANCE.md gets the receipts: the -L kernel ladder with one-core
throughput per kernel, the UTF-8 numbers before and after the split
decode, the thread-count rules, and the tab and CJK cases stated as
divergences instead of hidden.
This commit is contained in:
2026-11-15 13:38:32 -05:00
parent 5d2aee2f1d
commit 35d121e6ea
2 changed files with 189 additions and 27 deletions
+70 -1
View File
@@ -35,6 +35,9 @@ laptop APU, which is where the rest of you live:
| lines, 1B solo | **266 ms.** 11 GB in one pass at 41.4 GB/s — 3.76 billion lines per second. We are the reference now. |
| stdin lines, 10M | **4.6 ms vs coreutils 5.9 ms (1.28x).** Busybox 16.6x (161 ms), toybox 16.8x (154 ms). |
| stdin words, 1M | **1.5 ms vs coreutils 7.1 ms (4.7x).** GNU reads stdin like it's 1985. Busybox 12.7x, toybox 10.4x. |
| longest line, 110 MB | **10.4 ms vs coreutils 157 ms (15.1x).** Busybox 23.9x, toybox 21.0x. `-L` used to be our *worst* case. It isn't any more. |
| longest line, 1.1 GB | **61.5 ms vs coreutils 1.51 s (24.5x).** Busybox and toybox are not invited to this one. |
| 1050 files of 1 MiB, `-lwc` | **45 ms vs coreutils 1.51 s (33.5x).** A thousand small files is a scheduling problem, not a counting problem. |
Measured on an AMD Ryzen AI 7 PRO 350 — 8 cores / 16 threads, boost up
to 5.09 GHz, 384 KiB L1d / 256 KiB L1i / 8 MiB L2 / 16 MiB L3 — with
@@ -93,7 +96,7 @@ excluded from the averages — because nobody should be racing startup,
least of all a word counter. The cases that matter are the ones where
counting takes longer than starting — and those are the ones in this
table. Every run ends with the average speedup against each oracle —
coreutils ~4.5x, busybox ~13-15x, toybox ~15-18x — so the cruelty is
coreutils ~8-9x, busybox ~37-47x, toybox ~32-36x — so the cruelty is
quantified.
## Why
@@ -108,6 +111,17 @@ quantified.
now: regular files are mapped and counted in parallel across cores,
with SIMD kernels (AVX-512, AVX-2, SSE2) dispatched at runtime —
zero function calls in the hot path.
- **`-L` is not an afterthought.** The longest-line pass used to be the
one thing this program was bad at, because a line's width depends on
where it starts, which looks sequential. It isn't: a slice that begins
at a line end folds by maximum. Sixty-four bytes at a time, the
printable lanes are prefix-summed and the values at the line ends are
packed together, so one subtract yields every line width in the block.
24x faster than GNU on 1.1 GB, and 2.3x faster than the Rust clone
that used to beat us at it.
- **A long file list is a scheduling problem.** Past eight files the list
runs on a worker pool, one file per worker, rows still in argument
order. A thousand megabyte files take 45 ms; GNU takes 1.5 s.
- **GNU wc slows down in the locale you actually run.** Under a UTF-8
locale it decodes every byte it counts — pure ASCII included, which
decoding cannot change — so the 11 MB words file that takes it
@@ -115,6 +129,61 @@ quantified.
fastwc's kernels probe for non-ASCII bytes as they count and only
decode files that need it. The locale that taxes GNU is free for us.
## The other fastwc
There is another project called fastwc. It is written in Rust, which it
mentions. Every build of it compiles a tree of crates with a progress
bar, the way Rust does, and the result is a word counter that was, for a
few months, faster than ours at `-L`.
It posted 22x, and it had earned it. We were walking the file one byte at
a time, in one thread, while it split the mapping at newlines and ran an
AVX-2 width kernel per chunk. Good idea, honestly. So we took it, and
then took it further, because an old dog can learn new tricks and then
bite with them.
| case | that fastwc | this fastwc |
|------|------------:|------------:|
| `-L`, 110 MB | 21.4 ms | **10.4 ms** |
| `-L`, 1.1 GB | 142 ms | **61.5 ms** |
| `-L`, 11 GB | 1.29 s | **0.56 s** |
| 1050 × 1 MiB, `-lwc` | 145 ms | **45 ms** |
| 1050 × 1 MiB, `-L` | 1.23 s | **66 ms** |
Same files, same machine, both binaries racing the clock back to back.
Read the last row twice: on a thousand small files we are eighteen times
faster at the one thing it used to win, because the width kernel now
computes a whole 64-byte block's line widths with prefix sums and one
packed subtract, and a long file list is spread over the cores instead of
counted one file at a time.
Rust is the femboy language of systems programming: spotless hygiene,
elaborate safety equipment, and a firm opinion about how you should be
holding its hand. Memory safety is a fine goal for people who cannot
remember a few extra facts about a language. The rest of us have
`-Wall -Wextra`, a benchmark that fails on a single miscounted word, and
a self-test that runs every kernel against a scalar reference — which has
caught more real bugs in this one file than a borrow checker ever caught
in a program whose job is to read a file and add up three numbers. We'll
keep the pointers.
To be fair to their code: the `par_iter` over newline chunks is the right
shape, and their AVX-2 segment walk is clever. Rust isn't why they are
slower. Arithmetic is. A 32-byte AVX-2 block gives you one mask per
instruction; a 64-byte block with a prefix sum gives you every line width
in the block for one subtract, and after that the block costs the same
whether it holds one line or sixty. That isn't a language feature. It's
maths their kernel doesn't do, and ours does.
The same goes for the locale. Their "decode only around the high bytes"
instinct was right, so the UTF-8 path now splits the mapping into chunks
that decode independently and hands every ASCII stretch to the byte
kernels. 10 MB of lightly thé'd text under `en_US.UTF-8`: **1.6 ms**,
against their 2.8 ms and GNU's 30 ms. Dense CJK is the one place they
still edge us on `-w` and `-m`, because they carry their own width table
and we call `wcwidth` so the counts match GNU exactly. We are five times
ahead of GNU there and we will take the trade.
## What it does
```