Closed Bug 588990 Opened 14 years ago Closed 13 years ago

Remove lazy hashing of names to avoid walking full DOM

Categories

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

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: sicking, Assigned: sicking)

References

Details

Attachments

(1 file, 1 obsolete file)

We currently don't store elements in the name table until someone has looked up a given name. However this means that once someone looks up a specific name for the first time, we can't check the hash for it, but have to walk the full DOM.

It should be more efficient to simply hash all names as they come in. Patch coming up.
Jonas, did this patch ever happen?
Attached patch WIP (obsolete) — Splinter Review
This has been sitting in my tree for a while and should work. However it needs tests so not requesting review just yet.
Assignee: nobody → jonas
Attached patch Patch to fixSplinter Review
This'll do it. I found two other bugs while writing these tests:

1. Bug 307415
2. Bug 649415
Attachment #478826 - Attachment is obsolete: true
Attachment #525441 - Flags: review?(bzbarsky)
Comment on attachment 525441 [details] [diff] [review]
Patch to fix

r=me on the specialpowers patch, which I'm going to use in my patch in bug 650543.

Also, could you please let extensions/spellcheck/hunspell/tests/suggestiontest/Makefile.orig remain in the tree?  :-)
Why is nsHTMLDocument::ResolveName using PutEntry instead of GetEntry?

This patch changes our behavior on this testcase:

  data:text/html,<img name="write"><script>alert(document.write)</script>

but I _think_ it changes towards better compat with other browsers... Please check IE?

Is there a point to populating the name map for non-HTML documents?  If not, is it worth optimizing out the add/remove bits for non-HTML documents (I realize we want them for XHTML, so mIsRegularHTML is the wrong thing to check, but...)
(In reply to comment #6)
> Why is nsHTMLDocument::ResolveName using PutEntry instead of GetEntry?

When I made similar code refactoring for the id code I tried changing PutEntry to GetEntry. However that caused a measurable slowdown on the relevant Dromaeo tests. Apparently our hash table is faster when a lookup succeeds. 

> This patch changes our behavior on this testcase:
> 
>   data:text/html,<img name="write"><script>alert(document.write)</script>
> 
> but I _think_ it changes towards better compat with other browsers... Please
> check IE?

I checked with other browsers and no others had the same behavior as us. IIRC this patch aligned us with everyone else, and definitely with IE.

> Is there a point to populating the name map for non-HTML documents?  If not,
> is it worth optimizing out the add/remove bits for non-HTML documents (I
> realize we want them for XHTML, so mIsRegularHTML is the wrong thing to
> check, but...)

We could, I don't feel strongly. It does seem somewhat unlikely that there will be significant amounts of named non-form-control HTML contents in non-HTML documents (note that no form controls show up in the CanHaveName list).
> However that caused a measurable slowdown on the relevant Dromaeo tests.

See bug 572614 comment 2 and bug 572614 comment 3.
There you go :) I'll switch to GetEntry then :)
Comment on attachment 525441 [details] [diff] [review]
Patch to fix

OK, r=me with the change to GetEntry and corresponding comment adjustments.
Attachment #525441 - Flags: review?(bzbarsky) → review+
Looks like you could have removed the NAME_NOT_VALID define?
Checked in. Thanks for the review!

Of course, I forgot to remove the part of the patch that killed Makefile.orig, so I had to land a followup which added it back.

http://hg.mozilla.org/mozilla-central/rev/ea254208e04c
http://hg.mozilla.org/mozilla-central/rev/de123d952abd
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Depends on: 680922
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: