Change CData._data from []const to String (SSO)

After looking at a handful of websites, the # of Text and Commend nodes
that are small (<= 12 bytes) is _really_ high. Ranging from 85% to 98%. I
thought that was high, but a lot of it is indentation or a sentence that's
broken down into multiple nodes, eg:

<div><b>sale!</b> <span class=price>$1.99</span> buy now<div>

So what looks like 1 sentence to us, is actually 3 text nodes.

On a typical website, we should see thousands of fewer allocations in the
page arena for the text in text nodes.
This commit is contained in:
Karl Seguin
2026-02-27 12:53:54 +08:00
parent a14ad6f700
commit 870fd1654d
12 changed files with 252 additions and 98 deletions

View File

@@ -307,7 +307,11 @@ pub const Writer = struct {
try w.write(dom_node.getNodeName(&name_buf));
try w.objectField("nodeValue");
try w.write(dom_node.getNodeValue() orelse "");
if (dom_node.getNodeValue()) |nv| {
try w.write(nv.str());
} else {
try w.write("");
}
if (include_child_count) {
try w.objectField("childNodeCount");