wc: Assume long lines initially and find EOL with rawmemchr() - #351
Open
roman-zilka wants to merge 1 commit into
Open
roman-zilka wants to merge 1 commit into
roman-zilka wants to merge 1 commit into
Conversation
Start processing input by assuming its lines are long (>= 15 characters) and use rawmemchr() instead of checking individual bytes to find EOLs. The average line length in the distribution of linux-7.2.4 is 36 characters. Moving byte-by-byte is grossly suboptimal for long lines. Confirmed experimentally that the 15-character threshold is optimal: github.com/coreutils/pull/347#issuecomment-5653011937
Author
|
Also: $ A=$(for i in $(find /etc/ -type f); do file "$i"|grep ': ASCII text$' >/dev/null && cat "$i"; done | wc -l)
$ B=$(for i in $(find /etc/ -type f); do file "$i"|grep ': ASCII text$' >/dev/null && cat "$i"; done | wc -c)
$ echo $A $B $(( (B-A) / A ))
23603 744436 30 |
roman-zilka
added a commit
to roman-zilka/coreutils
that referenced
this pull request
Sep 13, 2026
Estimate the length of lines in input and choose a method of finding EOLs appropriately to increase performance: memchr() for long lines, manual byte-wise search for short lines. Long-short threshold = 15, experimentally: github.com/coreutils/pull/347#issuecomment-5653011937 Initial guess = long lines, based on Linux sources and /etc: coreutils#351
Author
|
Well, now I built coreutils with a simple |
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.
Start processing input by assuming its lines are long (>= 15 characters) and use
rawmemchr()instead of checking individual bytes to findEOLs. The average line length in the distribution of linux-7.2.4 is 36 characters. Moving byte-by-byte is grossly suboptimal for long lines.Confirmed experimentally that the 15-character threshold is optimal.