perf: avoid full string scans in StrEllipsis - #2557
Merged
Merged
Conversation
UTF8Length and UTF8Copy walk every byte of the input, and StrEllipsis runs for each rendered grid cell, so large TEXT/BLOB values were fully scanned on every paint. Exit early when the byte count already proves there is nothing to cut, and resolve the left-hand cut position with UTF8CodepointToByteIndex, which only walks the first MaxLen codepoints. Output is unchanged - verified against the previous implementation with 10k randomized mixed ASCII/Korean/emoji strings plus boundary cases. Still cuts on UTF-8 codepoint boundaries.
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.
Follow-up to the discussion on twinn1013/HeidiSQL@713e484e — rebased onto the current lazarus branch, on top of the UTF8Copy-based version.
UTF8LengthandUTF8Copywalk every byte of the input, andStrEllipsisruns for each rendered grid cell, so large TEXT/BLOB values get fully scanned on every paint. This change:UTF8CodepointToByteIndex, which only walks the firstMaxLencodepoints, and truncates in placeOutput is unchanged: verified against the current implementation with 10,000+ randomized mixed ASCII/Korean/emoji strings plus boundary cases — identical results in all of them, so it still cuts on UTF-8 codepoint boundaries and keeps the #2500 fix intact.
Benchmark (200,000 calls on a 10 MB string, MaxLen=100): ~64 ms with this change, while the current implementation needs ~16 ms per single call (it scans the whole 10 MB every time).