Say what the multibyte block kernel changed, and where it still loses
The 100 MB numbers replace the 10 MB ones, because 10 MB was measuring process startup as much as the decoder. Characters in dense CJK now beat the clone by 2.5x; words and longest line still lose to it by a quarter, which the divergences section says out loud instead of leaving the reader to find it. The -c and -m rows join the head-to-head table: no stream is opened for a count that is a file size.
This commit is contained in:
+28
-17
@@ -158,8 +158,11 @@ half and then the honest reporting:
|
||||
6. **No work that isn't asked for.** `-c` on a regular file is `st_size`
|
||||
from `fstat` — GNU figured that one out too, so we copied the good
|
||||
idea, and extended it to `-m` in a single-byte locale, where a
|
||||
character is a byte. `-l` without `-w` skips the whitespace mask
|
||||
entirely; `-w` without `-L` never builds the print table.
|
||||
character is a byte. Then we stopped opening a stream for it at all:
|
||||
the size the column width was computed from is the answer, so a
|
||||
thousand small files cost the stat pass and a row each. `-l` without
|
||||
`-w` skips the whitespace mask entirely; `-w` without `-L` never
|
||||
builds the print table.
|
||||
7. **ASCII pays nothing, even in a UTF-8 locale.** Multibyte decoding is
|
||||
expensive, so we don't volunteer for it. A sample of the first few
|
||||
KiB and two points in the middle decides whether a file is worth
|
||||
@@ -200,19 +203,26 @@ The UTF-8 decoder used to be the same story: correct, GNU-exact, and
|
||||
serial. It paid for every byte of a file, after a probe pass had already
|
||||
read the whole thing once. Now a UTF-8 file is split at line ends, each
|
||||
chunk decodes without inheriting state, ASCII stretches go to the byte
|
||||
kernels, and only the characters around a high byte are decoded. 10 MB
|
||||
under `en_US.UTF-8`:
|
||||
kernels, and dense CJK is counted a 64-byte block at a time from masks:
|
||||
characters as bytes minus continuations, lines from the newline mask,
|
||||
words from a byte-level white-space mask. A block that is not exactly
|
||||
ASCII plus three-byte characters is refused and decoded the slow way, so
|
||||
the fast path never guesses. 100 MB under `en_US.UTF-8`:
|
||||
|
||||
| case | before | after | Rust clone | GNU |
|
||||
|------|-------:|------:|-----------:|----:|
|
||||
| words, lightly multibyte | 26.7 ms | **1.6 ms** | 2.8 ms | 30.2 ms |
|
||||
| words, dense CJK | 33.8 ms | **7.8 ms** | 2.7 ms | 38.9 ms |
|
||||
| longest line, dense CJK | 43.0 ms | **11.5 ms** | 6.0 ms | 46.8 ms |
|
||||
| words, lightly multibyte | 6.8 ms | **5.5 ms** | 6.2 ms | 224 ms |
|
||||
| longest line, lightly multibyte | 26.2 ms | **9.1 ms** | 11.6 ms | 223 ms |
|
||||
| characters, dense CJK | 46.2 ms | **7.6 ms** | 18.7 ms | 458 ms |
|
||||
| words, dense CJK | 55.8 ms | **8.6 ms** | 6.8 ms | 464 ms |
|
||||
| longest line, dense CJK | 59.1 ms | **43.1 ms** | 33.7 ms | 587 ms |
|
||||
|
||||
Dense CJK is the one case the clone still wins, because it carries a
|
||||
width table and we call `wcwidth` so the counts agree with GNU on every
|
||||
code point. We are 5x ahead of GNU there; the parity we care about is
|
||||
with the oracle, not with the clone.
|
||||
The clone still wins words and longest line on dense CJK, by 26% and
|
||||
28%, because it carries its own width table and trusts the encoding where
|
||||
we validate and call `wcwidth`. Both of us are 20 to 50 times ahead of
|
||||
GNU there, and on everything else - ASCII, lightly multibyte text,
|
||||
characters in any mix - we are ahead of the clone. This is the honest
|
||||
state of the one case it still owns.
|
||||
|
||||
## Threads you actually have
|
||||
|
||||
@@ -251,12 +261,13 @@ locales, binary and UTF-8 data, every flag combination) passes 100%.
|
||||
|
||||
## Known divergences, stated plainly
|
||||
|
||||
- **Dense CJK is not where we win.** `-w` and `-m` over text that is
|
||||
multibyte end to end decode a character at a time, because a correct
|
||||
count needs `wcwidth`/`iswspace` per code point. The Rust clone carries
|
||||
its own table and is 2-3x faster there. Both of us are 5x faster than
|
||||
GNU, which is the number the contract cares about, and ASCII — the case
|
||||
that actually shows up in a shell — takes the byte kernels.
|
||||
- **Dense CJK still belongs to them on two flags.** `-w` and `-L` over
|
||||
text that is multibyte end to end are 26% and 28% behind the Rust
|
||||
clone, which carries its own width table and does not validate the
|
||||
encoding. We validate every block and call `wcwidth`, because the
|
||||
counts have to match GNU on every code point, and both of us are 20 to
|
||||
50 times ahead of GNU there. Characters (`-m`) and every ASCII or
|
||||
lightly multibyte case are ours.
|
||||
- **A tab-heavy block walks its runs.** The prefix-sum width kernel
|
||||
assumes a printable byte is worth one column. A tab is worth between
|
||||
one and eight depending on where in the line it sits, so any block
|
||||
|
||||
Reference in New Issue
Block a user