Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validity criteria for StaticRange #1009

Merged
merged 3 commits into from
Aug 31, 2021

Conversation

dandclark
Copy link
Contributor

@dandclark dandclark commented Aug 27, 2021

Add criteria defining whether a StaticRange is valid.

This will be used by the CSS Highlight API to determine whether or not to paint highlights specified by StaticRanges. See https://drafts.csswg.org/css-highlight-api-1/#range-invalidation (which will be updated to point to the DOM spec definition) and the CSSWG resolution that Highlight API should use StaticRanges internally rather than backing them with live Ranges.

Resolves #947.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

dom.bs Outdated Show resolved Hide resolved
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to clarify that w3c/csswg-drafts#4597 (comment) is intentional before we move ahead with this, but overall this seems reasonable to me.

Have any measurements been done to show that this is indeed faster?

cc @smaug----

@dandclark
Copy link
Contributor Author

It would be good to clarify that w3c/csswg-drafts#4597 (comment) is intentional before we move ahead with this, but overall this seems reasonable to me.

Commented here.

Have any measurements been done to show that this is indeed faster?

cc @smaug----

Yes, @ffiori built some benchmarks for this and ran them on Chromium's Highlight API prototype, with the findings documented here. As expected, adding a large number of live Ranges to a document increases the cost of DOM node moves due to the cost of keeping the Ranges up-to-date for every DOM operation. For StaticRange, these costs were avoided, and since it's possible to cache the results of the validity checks StaticRanges were in some cases significantly fater, and never significantly slower.

@smaug----
Copy link
Collaborator

Use of StaticRanges forces one to use MutationObserver or other mechanisms to detect mutations in order to keep StaticRanges up-to-date all the time, so the tests were very much unrealistic.
(Also, live Ranges need to observe changes only in the subtree they live in
"The Document stores a collection of pointers to all the Ranges that are alive inside it.
Whenever there’s a DOM mutation that involves deletion/addition of nodes or text for example, all these Ranges are notified about the mutation." smells like some implementations have rather heavyweight Ranges, but that is an implementation detail.)

But anyhow, this change as such is fine.

dom.bs Show resolved Hide resolved
@annevk annevk merged commit 29bd4c3 into whatwg:main Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Define criteria for StaticRange validation
3 participants