ext/dom: Avoid fetching the class attribute value twice - #23417
ext/dom: Avoid fetching the class attribute value twice#23417LamentXU123 wants to merge 1 commit into
Conversation
|
|
||
| - DOM: | ||
| . Made splitText() faster and consume less memory. | ||
| . Improved performance and reduced memory usage when updating Dom\TokenList |
There was a problem hiding this comment.
The premise doesn't hold. php_libxml_attr_value() only calls xmlNodeGetContent() when the attribute has more than one child; with a single text child it returns a borrowed pointer and allocates nothing. A class attribute is only split across children straight out of the parser with an unsubstituted entity reference, and every write collapses it back via xmlSetNsProp() or a single xmlNewDocText(). Verified at runtime on libxml2 2.15.3.
The constructor already fetched once and still does. The duplicate removed here is in ensure_set_up_to_date, which only runs once the value changed, by which point the attribute is collapsed. So this saves one xmlHasNsProp() lookup, not an allocation. Two million forced rebuilds showed no difference outside noise.
No allocation is avoided and no performance change is measurable.
|
This seems reasonable. I will take a closer look later. Thank you! |
DOMTokenList already retrieves the class attribute value when checking whether its cached token set is stale. And When rebuilding the set, the same value was fetched again.
So here, For attributes consisting of multiple child nodes, fetching the value calls xmlNodeGetContent and we can actually optimize this process by removing this redundant allocation.