cut: fix more compat issues - #13194
Draft
sylvestre wants to merge 3 commits into
Draft
Conversation
|
GNU testsuite comparison: |
collinfunk
reviewed
Jun 29, 2026
collinfunk
reviewed
Jun 29, 2026
collinfunk
reviewed
Jun 29, 2026
collinfunk
reviewed
Jun 29, 2026
collinfunk
reviewed
Jun 29, 2026
Merging this PR will degrade performance by 26.55%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | cut_characters |
17.1 ms | 23.3 ms | -26.55% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing sylvestre:mb-non-utf8 (e34f4db) with main (4e95dfe)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
65 tasks
sylvestre
force-pushed
the
mb-non-utf8
branch
2 times, most recently
from
July 4, 2026 16:36
523d612 to
5919e1d
Compare
sylvestre
force-pushed
the
mb-non-utf8
branch
3 times, most recently
from
August 2, 2026 08:23
79b2f7b to
e2f69cc
Compare
sylvestre
marked this pull request as draft
August 2, 2026 08:25
wasmtime's argument marshaling requires valid UTF-8, so a raw non-UTF-8 byte delimiter can't be passed through to the WASI binary the way it can natively on Linux.
The character path walked the line one character at a time through the encoding decoder and looked the locale encoding up per character, which dominated the per-line cost on mixed ASCII and multi-byte text. Take runs of ASCII bytes a machine word at a time. They are single-byte characters in every encoding handled here, so byte offset and character position move together across a run, and only the bytes above 0x7F need the decoder. Bundle the parts that are fixed for the whole run -- the ranges, the output delimiter and whether it was given, the position mode and the encoding -- into a CharCut built once by cut_chars, and make the line body a method on it, so the per-line call passes one pointer rather than seven arguments. In uucore, MbEncoding becomes the public Encoding and locale_encoding() returns it by value, so a caller decoding many characters resolves the locale once and keeps it in a register instead of reaching through a OnceLock per character. is_multibyte_locale() had no callers left. Instruction counts against the parent commit (cachegrind, LC_ALL=C.UTF-8): -c 5-30, 100k mixed short lines 30.44M -> 28.95M -c 20-70, 20k long multibyte lines 44.38M -> 41.02M That is roughly 1.1x in wall clock on both shapes; the machine was too loaded to quote a tighter figure. The single-byte path (LC_ALL=C) and field mode are unchanged. Selecting a range of characters still costs more than the same range of bytes, and always will: -c used to be an alias for -b, and characters have to be decoded to be counted. Tests cover advance directly -- character counting for -c, byte counting for -b -n, and the word boundary crossings -- plus a cut -c case over mixed ASCII and multi-byte lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add locale-aware character handling so -c counts characters, -b -n keeps multibyte characters whole, and -d accepts a single multibyte delimiter.
Should make test tests/cut/mb-non-utf8.sh pass