Files
tubestation/widget/tests
Masayuki Nakano 43a8855b80 Bug 1892514 - part 10: Make IMEContentObserver keep using mAddedContentCache while editor handles an editing command r=smaug
Each DOM API call like `nsINode::InsertNodeBefore` creates a document change
transaction.  Currently, `IMEContentObserver` flushes to pending text change
notification caused by new content nodes added in a document change when it
ends or begins another one.  So, we need to make `IMEContentObserver` cache new
content nodes across document changes to save the number of flattened text
offset/length computation for our editor.

Currently, `mAddedContentCache` can store nodes in different containers to
improve the performance of setting `innerHTML` (bug 1250823).  However, if we
allow this in multiple document changes, we may need to compare new node
strictly and it may be too expensive for the hot path.  We can reduce the
comparing cost if we make `mAddedContentCache` cache only siblings in same
container node.  Then, we can compare new inserted nodes with parent node
check and computing indices in the parent node.  Fortunately, notifications
during setting `innerHTML` was optimized in bug 1882417 which made notifies
observers only of appended children.  For fixing bug 1892514, we need to
store new nodes in same container.  Therefore, we can make `mAddedContentCache`
store only sibling nodes.

When a document change ends while the editor is handling an edit operation,
`IMEContentObserver` should not compute a text change for the new added nodes
because it can compute it when the editor ends handling the operation or new
content node is not a direct sibling in the cached range.  Therefore, this
can save the number of computing start of first added content nodes once per
the container (except when new nodes inserted in same container but not
adjacent to the cached range).

In other words, this patch does not optimize the case when JS inserts a lot of
nodes with calling DOM API with a loop. I have no idea how to optimize this
case, but currently there is no performance bug for this.  Therefore, I don't
fix this now.

Make AddedContentCache work only in the siblings mode

Differential Revision: https://phabricator.services.mozilla.com/D211709
2024-07-03 08:04:30 +00:00
..