Skip to content

perf: avoid full string scans in StrEllipsis - #2557

Merged
ansgarbecker merged 1 commit into
HeidiSQL:lazarusfrom
twinn1013:strellipsis-performance
Jul 20, 2026
Merged

perf: avoid full string scans in StrEllipsis#2557
ansgarbecker merged 1 commit into
HeidiSQL:lazarusfrom
twinn1013:strellipsis-performance

Conversation

@twinn1013

Copy link
Copy Markdown
Collaborator

Follow-up to the discussion on twinn1013/HeidiSQL@713e484e — rebased onto the current lazarus branch, on top of the UTF8Copy-based version.

UTF8Length and UTF8Copy walk every byte of the input, and StrEllipsis runs for each rendered grid cell, so large TEXT/BLOB values get fully scanned on every paint. This change:

  • exits early when the byte count already proves there is nothing to cut (a string with ≤ MaxLen bytes can never contain more than MaxLen codepoints) — the common case costs nothing
  • resolves the left-hand cut position with UTF8CodepointToByteIndex, which only walks the first MaxLen codepoints, and truncates in place

Output 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).

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.
@twinn1013 twinn1013 self-assigned this Jul 20, 2026
@ansgarbecker
ansgarbecker merged commit 32f3bd0 into HeidiSQL:lazarus Jul 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants