fix(text): avoid spurious measuring in _measureChar when only kerning-irrelevant entries are missing#11028
Open
jiayihu wants to merge 2 commits into
Open
fix(text): avoid spurious measuring in _measureChar when only kerning-irrelevant entries are missing#11028jiayihu wants to merge 2 commits into
jiayihu wants to merge 2 commits into
Conversation
…-irrelevant entries are missing
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Contributor
|
Build Stats
|
asturur
reviewed
Jun 29, 2026
| if (previousChar && fontCache.has(previousChar)) { | ||
| previousWidth = fontCache.get(previousChar); | ||
| if (hasPrevChar && fontCache.has(previousChar!)) { | ||
| previousWidth = fontCache.get(previousChar!); |
Member
There was a problem hiding this comment.
is incredible that TS still can't catch this.
Contributor
Author
There was a problem hiding this comment.
My bad (or GLM's so ultimately mine eheh). It was using Boolean, which defeats the TS control flow analysis. Using raw !! preserves it. Still needed for Maps though as there is no control flow analysis for Map.has
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.
Disclosure: I found out the issue during work but I fully asked GLM 5.2 to port the fix back to fabric, add tests and open the PR using the repo skill.
Summary
_measureCharwas treating missingpreviousWidthorcoupleWidthas a cache miss even when kerning was irrelevant (no usable previous char, or previous char with a different style). On a pure single-character cache hit this forced an unnecessary fetch of the measuring context and extra_setTextStyles/measureTextbookkeeping. The fix only builds and reads the kerning pair when a same-style previous char exists, and only enters the measuring path when the single-character width is missing or a same-style kerning pair actually needs measuring.Changes
src/shapes/Text/Text.ts: rewrote the_measureCharcache/measure logic so the couple key andpreviousWidthare only built/read whenpreviousCharexists, and the measuring path is gated onwidth === undefined || (stylesAreEqual && coupleWidth === undefined).src/shapes/Text/Text.spec.ts: added two tests covering the regression — one asserting_setTextStylesis not called when only kerning-irrelevant entries are missing, and one assertingmeasureTextis invoked forpreviousWidthandcoupleWidth(and not for an already-cached single char) when both are undefined.