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:
@@ -149,13 +149,16 @@ bite with them.
|
|||||||
| `-L`, 11 GB | 1.29 s | **0.56 s** |
|
| `-L`, 11 GB | 1.29 s | **0.56 s** |
|
||||||
| 1050 × 1 MiB, `-lwc` | 145 ms | **45 ms** |
|
| 1050 × 1 MiB, `-lwc` | 145 ms | **45 ms** |
|
||||||
| 1050 × 1 MiB, `-L` | 1.23 s | **66 ms** |
|
| 1050 × 1 MiB, `-L` | 1.23 s | **66 ms** |
|
||||||
|
| 1050 × 1 MiB, `-c` | 3.7 ms | **2.1 ms** |
|
||||||
|
| 1050 × 1 MiB, `-m` | 30.8 ms | **2.7 ms** |
|
||||||
|
|
||||||
Same files, same machine, both binaries racing the clock back to back.
|
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
|
Read the `-L` 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
|
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
|
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
|
packed subtract, and a long file list is spread over the cores instead of
|
||||||
counted one file at a time.
|
counted one file at a time. The `-c` and `-m` rows are the other half of
|
||||||
|
that: a count that is a file size never opens the file.
|
||||||
|
|
||||||
Rust is the femboy language of systems programming: spotless hygiene,
|
Rust is the femboy language of systems programming: spotless hygiene,
|
||||||
elaborate safety equipment, and a firm opinion about how you should be
|
elaborate safety equipment, and a firm opinion about how you should be
|
||||||
@@ -176,13 +179,16 @@ whether it holds one line or sixty. That isn't a language feature. It's
|
|||||||
maths their kernel doesn't do, and ours does.
|
maths their kernel doesn't do, and ours does.
|
||||||
|
|
||||||
The same goes for the locale. Their "decode only around the high bytes"
|
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
|
instinct was right, so the UTF-8 path splits the mapping into chunks that
|
||||||
that decode independently and hands every ASCII stretch to the byte
|
decode independently, hands every ASCII stretch to the byte kernels, and
|
||||||
kernels. 10 MB of lightly thé'd text under `en_US.UTF-8`: **1.6 ms**,
|
counts dense CJK a 64-byte block at a time from masks rather than a
|
||||||
against their 2.8 ms and GNU's 30 ms. Dense CJK is the one place they
|
character at a time. 100 MB of lightly thé'd text under `en_US.UTF-8`:
|
||||||
still edge us on `-w` and `-m`, because they carry their own width table
|
**5.5 ms**, against their 6.2 and GNU's 224. On dense CJK characters we
|
||||||
and we call `wcwidth` so the counts match GNU exactly. We are five times
|
are 7.6 ms against their 18.7; on CJK words and longest line they still
|
||||||
ahead of GNU there and we will take the trade.
|
have us by a quarter, because they keep a width table and trust the
|
||||||
|
encoding where we validate and call `wcwidth` to match GNU exactly. We
|
||||||
|
will take a quarter of a loss on two flags of one alphabet for exact
|
||||||
|
counts on all of them.
|
||||||
|
|
||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
|
|||||||
+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`
|
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
|
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
|
idea, and extended it to `-m` in a single-byte locale, where a
|
||||||
character is a byte. `-l` without `-w` skips the whitespace mask
|
character is a byte. Then we stopped opening a stream for it at all:
|
||||||
entirely; `-w` without `-L` never builds the print table.
|
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
|
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
|
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
|
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
|
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
|
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
|
chunk decodes without inheriting state, ASCII stretches go to the byte
|
||||||
kernels, and only the characters around a high byte are decoded. 10 MB
|
kernels, and dense CJK is counted a 64-byte block at a time from masks:
|
||||||
under `en_US.UTF-8`:
|
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 |
|
| case | before | after | Rust clone | GNU |
|
||||||
|------|-------:|------:|-----------:|----:|
|
|------|-------:|------:|-----------:|----:|
|
||||||
| words, lightly multibyte | 26.7 ms | **1.6 ms** | 2.8 ms | 30.2 ms |
|
| words, lightly multibyte | 6.8 ms | **5.5 ms** | 6.2 ms | 224 ms |
|
||||||
| words, dense CJK | 33.8 ms | **7.8 ms** | 2.7 ms | 38.9 ms |
|
| longest line, lightly multibyte | 26.2 ms | **9.1 ms** | 11.6 ms | 223 ms |
|
||||||
| longest line, dense CJK | 43.0 ms | **11.5 ms** | 6.0 ms | 46.8 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
|
The clone still wins words and longest line on dense CJK, by 26% and
|
||||||
width table and we call `wcwidth` so the counts agree with GNU on every
|
28%, because it carries its own width table and trusts the encoding where
|
||||||
code point. We are 5x ahead of GNU there; the parity we care about is
|
we validate and call `wcwidth`. Both of us are 20 to 50 times ahead of
|
||||||
with the oracle, not with the clone.
|
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
|
## Threads you actually have
|
||||||
|
|
||||||
@@ -251,12 +261,13 @@ locales, binary and UTF-8 data, every flag combination) passes 100%.
|
|||||||
|
|
||||||
## Known divergences, stated plainly
|
## Known divergences, stated plainly
|
||||||
|
|
||||||
- **Dense CJK is not where we win.** `-w` and `-m` over text that is
|
- **Dense CJK still belongs to them on two flags.** `-w` and `-L` over
|
||||||
multibyte end to end decode a character at a time, because a correct
|
text that is multibyte end to end are 26% and 28% behind the Rust
|
||||||
count needs `wcwidth`/`iswspace` per code point. The Rust clone carries
|
clone, which carries its own width table and does not validate the
|
||||||
its own table and is 2-3x faster there. Both of us are 5x faster than
|
encoding. We validate every block and call `wcwidth`, because the
|
||||||
GNU, which is the number the contract cares about, and ASCII — the case
|
counts have to match GNU on every code point, and both of us are 20 to
|
||||||
that actually shows up in a shell — takes the byte kernels.
|
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
|
- **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
|
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
|
one and eight depending on where in the line it sits, so any block
|
||||||
|
|||||||
Reference in New Issue
Block a user