Closed Bug 1385389 Opened 7 years ago Closed 7 years ago

Consider not deleting the common ancestor hashtable in nsRange::UnregisterCommonAncestor()

Categories

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

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 2 obsolete files)

Deleting this hashtable and recreating it shows up in profiles of bug 1346723. Perhaps we should consider not doing this extra work given how quickly selections can be changed by the user and script. This can cause us to use a bit more memory but this hashtable should be very small in most cases. The patch is simple, please feel free to r- if you disagree with the change.
Comment on attachment 8891458 [details] [diff] [review] Do not delete the common ancestor ranges hashtable in nsRange::UnregisterCommonAncestor() because chances are we need to recreate it shortly after This obviously wouldn't work, we need to remove the entry as well.
Attachment #8891458 - Attachment is obsolete: true
Attachment #8891458 - Flags: review?(bugs)
Comment on attachment 8891598 [details] [diff] [review] Do not delete the common ancestor ranges hashtable in nsRange::UnregisterCommonAncestor() because chances are we need to recreate it shortly after I guess we can try this, but I wonder about the memory use. I think I'd prefer to limit this to native anonymous content, for now.
Attachment #8891598 - Flags: review?(bugs)
Assignee: nobody → ehsan
Attachment #8891598 - Attachment is obsolete: true
Attachment #8896796 - Flags: review?(bugs) → review+
Pushed by eakhgari@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/ddc59dc7b92d Do not delete the common ancestor ranges hashtable in nsRange::UnregisterCommonAncestor() because chances are we need to recreate it shortly after; r=smaug
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Comment on attachment 8896796 [details] [diff] [review] Do not delete the common ancestor ranges hashtable in nsRange::UnregisterCommonAncestor() because chances are we need to recreate it shortly after >+ bool isNativeAnon = aNode->IsInNativeAnonymousSubtree(); >+ bool removed = false; >+ > if (ranges->Count() == 1) { > aNode->ClearCommonAncestorForRangeInSelection(); >- aNode->GetCommonAncestorRangesPtr().reset(); >+ if (!isNativeAnon) { >+ // For nodes which are in native anonymous subtrees, we optimize away the >+ // cost of deallocating the hashtable here because we may need to create >+ // it again shortly afterward. We don't do this for all nodes in order >+ // to avoid the additional memory usage unconditionally. >+ aNode->GetCommonAncestorRangesPtr().reset(); I'm confused at here. The comment says, "For nodes which are *in* native anonymous subtrees", but the block is used when IsInNativeAnonymousSubtree() returns *false*. Do I misunderstand something??
Flags: needinfo?(ehsan)
(In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #8) > Comment on attachment 8896796 [details] [diff] [review] > Do not delete the common ancestor ranges hashtable in > nsRange::UnregisterCommonAncestor() because chances are we need to recreate > it shortly after > > >+ bool isNativeAnon = aNode->IsInNativeAnonymousSubtree(); > >+ bool removed = false; > >+ > > if (ranges->Count() == 1) { > > aNode->ClearCommonAncestorForRangeInSelection(); > >- aNode->GetCommonAncestorRangesPtr().reset(); > >+ if (!isNativeAnon) { > >+ // For nodes which are in native anonymous subtrees, we optimize away the > >+ // cost of deallocating the hashtable here because we may need to create > >+ // it again shortly afterward. We don't do this for all nodes in order > >+ // to avoid the additional memory usage unconditionally. > >+ aNode->GetCommonAncestorRangesPtr().reset(); > > I'm confused at here. The comment says, "For nodes which are *in* native > anonymous subtrees", but the block is used when IsInNativeAnonymousSubtree() > returns *false*. Do I misunderstand something?? This is a double negative. If the node is not in a native anonymous subtree, we delete the hashtable, otherwise (that is, if the node is inside a native anonymous subtree) we leave the hashtable alone in the hope that it will be reused later.
Flags: needinfo?(ehsan)
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: