Closed Bug 372086 Opened 17 years ago Closed 17 years ago

Should ranges observe the common ancestor container instead?

Categories

(Core :: DOM: Core & HTML, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

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

Details

(Keywords: perf, regression)

Attachments

(3 files)

Right now ranges in a document observe the document.  This means that if you have a lot of ranges, all sorts of DOM manipulations become very slow.

For example, the large testcase in bug 352367 ends up with one range per textfield (the editor's selection).  As a result, a partial profile (I killed the app when the log file was nearing a gig) shows that 10% of the time is spent assigning document observers (most of them ranges) into nsCOMPtrs while notifying.  Given N textfields, this behavior makes the load O(N^2).  The constant is small, but that testcase seems to be big enough that this does not matter anymore...

Now we should work on lazy editor init for sure, but at the same time, it seems like it would make more sense for ranges to observe their common ancestor container, not the document...
Blocks: 352367
Unfortunately, we pass mRoot to nsContentUtils::ContentIsDescendantOf in nsRange::ComparePoint.  We also expose it via GetRoot().  Which means we have to notice when it goes away....  :(

I just realized that lots of editor is not the only thing that produces lots of ranges in common browsing.  Spellcheck on a large textarea will do the same thing.
Flags: blocking1.9?
Keywords: regression
Nevermind.  That wouldn't work well at all -- we want ranges to notice when an ancestor of an endpoint is being removed.

So let me try that in a different way.  ;)
Attached patch Maybe like soSplinter Review
After some consideration, perhaps we should do this.  I tested with <https://bugzilla.mozilla.org/attachment.cgi?id=143479> and selection with anon content is already broken enough that this won't really break it more.  And it makes a lot more sense than what we do now, imo.
Attachment #256771 - Flags: superreview?(jst)
Attachment #256771 - Flags: review?(jonas)
With that change, bug 236957 will become more or less moot, I think...
Blocks: 236957
Comment on attachment 256771 [details] [diff] [review]
Maybe like so

Lets try it and see if anything breaks
Attachment #256771 - Flags: superreview?(jst)
Attachment #256771 - Flags: superreview+
Attachment #256771 - Flags: review?(jonas)
Attachment #256771 - Flags: review+
Assignee: traversal-range → bzbarsky
Checked in.  Still need to write tests...
Status: NEW → RESOLVED
Closed: 17 years ago
Flags: blocking1.9? → in-testsuite?
Resolution: --- → FIXED
(In reply to comment #5)
>(From update of attachment 256771 [details] [diff] [review])
>Lets try it and see if anything breaks
void
nsRange::DoSetRange(nsINode* aStartN, PRInt32 aStartOffset,
                    nsINode* aEndN, PRInt32 aEndOffset,
                    nsINode* aRoot)
{
  NS_PRECONDITION((aStartN && aEndN && aRoot) ||
                  (!aStartN && !aEndN && !aRoot),
                  "Set all or none");
  NS_PRECONDITION(!aRoot ||
                  (!aRoot->GetNodeParent() &&
                   (aRoot->IsNodeOfType(nsINode::eDOCUMENT) ||
                    aRoot->IsNodeOfType(nsINode::eATTRIBUTE) ||
                    aRoot->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT))),
                  "Bad root");
Attachment #256930 - Flags: superreview?(jonas)
Attachment #256930 - Flags: review?(jonas)
Attachment #256930 - Flags: superreview?(jonas)
Attachment #256930 - Flags: superreview+
Attachment #256930 - Flags: review?(jonas)
Attachment #256930 - Flags: review+
Checked in the assertion check.
Depends on: 372470
Depends on: 374873
Attached patch MochitestSplinter Review
Checked that in.
Flags: in-testsuite? → in-testsuite+
Blocks: 312832
Depends on: 285594
Depends on: 384706
Depends on: 466568
Depends on: 666618
Depends on: 791632
Component: DOM: Traversal-Range → DOM: Core & HTML
Depends on: 1328030
Depends on: 1362873
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: