Skip to content

Add TreeBuilder::text and has_pending_whitespace; process tree builder text eagerly - #62

Draft
nicoburns wants to merge 6 commits into
mainfrom
devin/1790425683-tree-builder-text-so-far
Draft

nicoburns wants to merge 6 commits into
mainfrom
devin/1790425683-tree-builder-text-so-far

Conversation

@nicoburns

@nicoburns nicoburns commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

LLM Contributions: Code and this description were written by Devin (an LLM agent). The description needs rewriting by a human before this goes upstream.

Adds two getters to TreeBuilder:

  • text(&self) -> &str returns the text pushed so far, after white space processing. Trailing collapsible whitespace is not included.
  • has_pending_whitespace(&self) -> bool reports whether there is trailing collapsible whitespace. It becomes a single space if more content follows, or is removed otherwise.

Blitz needs these for text-transform: capitalize, which has to find word boundaries in the text before the current text node (DioxusLabs/blitz#947).

To keep the getters read-only, TreeStyleBuilder no longer buffers text in uncommitted_text, and push_text now applies white space processing straight away. The buffer was needed when collapsing trimmed whitespace at each span's start and end, which required all of a span's text before processing. Since linebender#786 that is handled by the streaming pending_whitespace state. splitting_text_does_not_affect_white_space_processing checks that splitting text across push_text calls at any char boundary gives the same text and style runs, in all four WhiteSpaceCollapse modes.

Performance was measured with TreeBuilder benchmarks that are kept separately in the draft PR stacked on this one. Tango comparison against the buffered version:

  • push, 10 chars per push_text (1 or 8 pushes per span): 0% to 41% faster. For example, latin 8000 chars with Preserve and 1 push per span went from 33.5 µs to 24.5 µs. The buffered version allocated a new buffer for every span.
  • push, 1 char per push_text with 10 pushes per span, the worst case: up to 31% slower, about 2–4 ns more per call.
  • build, including shaping: between −3% and +1.2%.
  • Blitz laying out the Barack Obama Wikipedia page: the text-push step was 1.2% faster, and the change in total layout time was within noise.

Changelog

Added

  • TreeBuilder::text and TreeBuilder::has_pending_whitespace, which return the white space processed text pushed so far and whether collapsible whitespace is pending after it.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/4641a2bf5eca4d4fb140d16886180423
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/4641a2bf5eca4d4fb140d16886180423?variant=devin-insiders
Requested by: @nicoburns

@staging-devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@staging-devin-ai-integration staging-devin-ai-integration Bot changed the title Add TreeBuilder::text_so_far Add TreeBuilder::text_so_far; process tree builder text eagerly Sep 26, 2026
@staging-devin-ai-integration staging-devin-ai-integration Bot changed the title Add TreeBuilder::text_so_far; process tree builder text eagerly Add TreeBuilder::text and has_pending_whitespace; process tree builder text eagerly Sep 28, 2026
@staging-devin-ai-integration
staging-devin-ai-integration Bot force-pushed the devin/1790425683-tree-builder-text-so-far branch from d1781b8 to fe83c41 Compare September 28, 2026 20:13
White space processing no longer needs to see a span's text all at once,
so push_text processes text immediately. This makes text_so_far a
read-only getter.
@staging-devin-ai-integration
staging-devin-ai-integration Bot force-pushed the devin/1790425683-tree-builder-text-so-far branch from fe83c41 to 6e57520 Compare September 28, 2026 20:21
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.

1 participant