Open Bug 2000528 Opened 10 months ago Updated 3 months ago

Support tokenizing from Latin1 in the innerHTML/DOMParser case

Categories

(Core :: DOM: HTML Parser, enhancement)

enhancement

Tracking

()

ASSIGNED

People

(Reporter: hsivonen, Assigned: hsivonen)

References

(Depends on 1 open bug, Blocks 3 open bugs)

Details

As documented in bug 1926474 comment 12, in Speedometer 3.1, most calls to the innerHTML setter (whether tokenizer bypasses or actual tokenizations) use Latin1 input (that does not contain ampersands).

We should support tokenizing directly from Latin1. There are two design axes that need decisions:

  1. Whether to support any Latin1 input or only Latin1 input that's guaranteed to generate Latin1 output, i.e. Latin1 input that does not contain '\0' or '&'.
  2. If any Latin1 input is supported, whether to flatten ropes or not.

In bug 1926474, I leaned towards supporting only Latin1 input that's guaranteed to produce Latin1 output. However, on further reflection, considering how element and attribute names are currently looked up with short buffers without SIMD and how attribute values are always UTF-16, it would probably not be too problematic to support dual text node buffers in the tree builder with checks if expansion to UTF-16 is needed.

Tentatively, I'm changing my opinion to try to support any Latin1 input, even '\0' or '&'.

In that case, it would be possible to tokenize per rope segment. The main downside of doing so is that it would defeat SIMD usage, because we'd fall off the SIMD path when reaching the tail of each rope segment instead of falling off the SIMD path only near the end of the whole input.

Tentatively, I think we should flatten the input and not let the tokenizer see the rope segments.

It makes sense to do bug 1998353 first, so marking this one as dependent on that one, even if it's not a strict ordering.

Depends on: 1998353

WPT: https://treeherder.mozilla.org/jobs?repo=try&landoInstance=lando-prod&landoCommitID=193694

This patch omits the ContainsMarkup check and walks the rope to parse it in the innerHTML setter. I'm worried about ropes with lots of tiny pieces, since there's a fixed cost per rope segment.

(In reply to Henri Sivonen (:hsivonen) from comment #1)

It makes sense to do bug 1998353 first, so marking this one as dependent on that one, even if it's not a strict ordering.

And it still makes sense to do that, but I'm pursuing this one first.

Furthermore, bug 2035718 and bug 2035717 look important pieces that we should do in order to optimize the perf here.

(In reply to Henri Sivonen (:hsivonen) from comment #3)

This patch omits the ContainsMarkup check and walks the rope to parse it in the innerHTML setter. I'm worried about ropes with lots of tiny pieces, since there's a fixed cost per rope segment.

One thing we could do is to have the ContainsMarkup rope walk discover what the rope is like so that we could make the decision to flatten the rope before tokenizing if it turns out to have lots of tiny pieces.

This appears to double the throughput for Latin1 text nodes, but this regresses the performance of handling quoted attribute values.

My current unverified reasoning is this:

Attribute values get expanded to UTF-16, so something causes expansion on a per-attribute value basis to be worse that expanding the whole HTML input string to begin with. When expansion is on a per-attribute value basis, there's an opportunity for a non-SIMD suffix (which may cover the entire attribute value so that there is no SIMD-friendly prefix at all) for every attribute value instead of the opportunity for a non-SIMD suffix once for the whole input.

One way to test this would be to make the per-attribute-value expansion round up to a multiple of 16 (when allocation bounds permit) to convert some trailing garbage, but since bug 1998353 is already a recognized opportunity, it makes sense to implement that first and do trailing garbage writes as part of that work (making the bet that using SIMD for non-garbage prefix outweighs the cost of writing trailing garbage).

You need to log in before you can comment on or make changes to this bug.