New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: improve utf_char2cells() performance #27353
Merged
Merged
Conversation
This file contains 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
zeertzjq
reviewed
Feb 5, 2024
You may also want to take #18690 into consideration. |
zeertzjq
added
performance
issues reporting performance problems
unicode 💩
(multibyte) unicode characters
labels
Feb 6, 2024
vanaigr
force-pushed
the
faster-char2cells
branch
from
February 7, 2024 02:27
f94aafe
to
ce39694
Compare
Should I make characters above 10FFFF unprintable? |
Hmm, actually it's not hard to add that check later, so not really necessary. |
zeertzjq
added
ci:s390x
Enable CI for s390x
and removed
ci:s390x
Enable CI for s390x
labels
Feb 7, 2024
zeertzjq
reviewed
Feb 7, 2024
vanaigr
force-pushed
the
faster-char2cells
branch
from
February 7, 2024 05:14
ce39694
to
c2491d7
Compare
zeertzjq
reviewed
Feb 7, 2024
ii14
approved these changes
Feb 7, 2024
vanaigr
force-pushed
the
faster-char2cells
branch
from
February 7, 2024 06:32
c2491d7
to
cc1ddce
Compare
Thanks so much everyone! |
glepnir
pushed a commit
to glepnir/neovim
that referenced
this pull request
Mar 31, 2024
`utf_char2cells()` calls `utf_printable()` twice (sometimes indirectly, through `vim_isprintc()`) for characters >= 128. The function can be refactored to call to it only once. `utf_printable()` uses binary search on ranges of unprintable characters to determine if a given character is printable. Since there are only 9 ranges, and the first range contains only one character, binary search can be replaced with SSE2 SIMD comparisons that check 8 ranges at a time, and the first range is checked separately. SSE2 is enabled by default in GCC, Clang and MSVC for x86-64. Add 3-byte utf-8 to screenpos_spec benchmarks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
utf_char2cells()
callsutf_printable()
twice (sometimes indirectly, throughvim_isprintc()
) for characters >= 128. The function can be refactored to call to it only once.utf_printable()
uses binary search on ranges of unprintable characters to determine if a given character is printable. Since there are only 9 ranges, and the first range contains only one character, binary search can be replaced with SSE2 SIMD comparisons that check 8 ranges at a time, and the first range is checked separately.SSE2 is enabled by default in GCC, Clang and MSVC for x86-64.
I tested the function and it returns the same results for all 2^32 values.
Benchmarks:
I modified the benchmarks from #26813 to better reflect the performance difference and added a new benchmark that measures 3 byte utf-8 separately.