optimised TextLayoutEngine#787
Open
jfboeve wants to merge 6 commits into
Open
Conversation
Collaborator
jfboeve
commented
May 7, 2026
- spread replaced with for loop
- shift / unshift replaced with wordIdx, spaceIdx, and a pendingWord string.
- infinite loop guard added
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes TextLayoutEngine’s text wrapping to reduce allocations and O(n) array operations during layout (spread/shift/unshift), and adds a guard intended to prevent infinite loops when no progress can be made during word splitting/truncation.
Changes:
- Replaced
wrappedLines.push(...wrappedLine)with an indexedforloop push. - Replaced
shift()/unshift()-based word/space consumption withwordIdx/spaceIdxindices and apendingWordbuffer. - Added an infinite-loop guard when a word cannot be reduced to any fitting characters.
|
|
Contributor
…788) This stacked PR addresses review feedback from #787: in the first-word overflow path (`wordWidth > maxWidth` on an empty line), output could be truncated while the emitted `TextLineStruct` incorrectly reported `truncated = false`. This made truncation state inconsistent with other wrap strategies and downstream consumers of `line[2]`. - **`wrapLine` truncation flag consistency** - In `src/core/text-rendering/TextLayoutEngine.ts`, updated the first-word overflow branch to propagate truncation intent into the emitted tuple: - mark `truncated` when last-line truncation is selected (`remainingLines` reaches 0), - keep `truncated` set when fallback output is emitted in the no-fit path. - Result: tuple metadata now matches actual rendered behavior in this edge case. - **Regression coverage update** - In `src/core/text-rendering/tests/TextLayoutEngine.test.ts`, extended the no-fit fallback regression to assert the truncation bit (`line[2]`) in addition to text output. ```ts // first word doesn't fit on an empty line wrappedLines.push([word, wordWidth, lineTruncated, 0, 0]); // regression expectation for no-fit fallback expect(result[0][0]?.[2]).toBe(true); ```
2 tasks
chiefcll
added a commit
to solid-tv/renderer
that referenced
this pull request
May 9, 2026
Port lightning-js/renderer#787: - Replace shift/unshift on words/spaces arrays with index pointers and a pendingWord string to avoid O(n^2) array reshuffling on long lines. - Replace spread push of wrappedLine with a for loop. - Guard against infinite loop when maxWidth is smaller than a single glyph plus the overflow suffix; force overflowSuffix (or single char) and end the line as truncated. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
wouterlucas
approved these changes
May 11, 2026
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.