Skip to content

Build a text node's context and children on first use - #765

Open
senid231 wants to merge 1 commit into
activeadmin:masterfrom
senid231:perf/lazy-text-node
Open

senid231 wants to merge 1 commit into
activeadmin:masterfrom
senid231:perf/lazy-text-node

Conversation

@senid231

@senid231 senid231 commented Dec 3, 2026

Copy link
Copy Markdown

Text nodes no longer build an Arbre::Context and a child collection when they are created. They build them the first time something reads them. TextNode.from_string, which wraps every string added to an element, passed no context, so Element#initialize created a full Context for each one. This is the change suggested in the review of #756, split out so its gain is measured on its own.

On a 500-row by 44-cell table, building the tree allocates 636k objects instead of 772k (42.4 MB instead of 54.0 MB). Rendering is unchanged, so this is about 5% of the bytes allocated overall. Wall time shows no measurable difference.

Freezing a text node builds both first, so a frozen node can still read them.

Verification: new examples in spec/arbre/unit/html/text_node_spec.rb. The 23 examples from #761 pass with this change.

TextNode.from_string called Element#initialize, which built an
Arbre::Context and a child collection for every text node. Few text
nodes ever read either.

Co-Authored-By: Clanker

This branch has not been deployed

No deployments
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