Closed Bug 396203 Opened 17 years ago Closed 17 years ago

Unify checks for DOMLinkAdded

Categories

(Firefox :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 3 beta1

People

(Reporter: rflint, Assigned: rflint)

References

Details

(Keywords: perf)

Attachments

(1 file, 3 obsolete files)

We currently register 3 distinct listeners for DOMLinkAdded[1] and then check whether the current link applies to any of three on every page load. This can be simplified to add only one listener and have all the checks run from a central location where we can bail once we have a match. [1]http://lxr.mozilla.org/seamonkey/source/browser/base/content/tabbrowser.xml#856 http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2675 http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#5242
Flags: blocking-firefox3?
Keywords: perf
Attached patch Patch + tests (obsolete) — Splinter Review
Attachment #281970 - Flags: review?(mconnor)
Attached patch Patch -w (obsolete) — Splinter Review
This also takes care of some wacky whitespace in BrowserSearch, so here's the same -w'd.
Attached patch Patch v1.1 (obsolete) — Splinter Review
Doh, fixed a couple typos.
Attachment #281970 - Attachment is obsolete: true
Attachment #281978 - Flags: review?(mconnor)
Attachment #281970 - Flags: review?(mconnor)
Comment on attachment 281978 [details] [diff] [review] Patch v1.1 >Index: base/content/browser.js ... >+ // setup our common DOMLinkAdded listener >+ gBrowser.addEventListener("DOMLinkAdded", >+ function (event) { DOMLinkHandler.onLinkAdded(event); }, >+ false); Why not |gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false)|? DOMLinkHandler could be a function or it could implement handleEvent. >+ var rel = link.rel && link.rel.toLowerCase(); >+ var rels = {}; >+ if (rel) { >+ for each (let relVal in rel.split(/\s+/)) >+ rels[relVal] = true; >+ } |for each| for arrays is slow. >+ else if (rels.search) { >+ var type = link.type && link.type.toLowerCase(); >+ type = type.replace(/^\s+/, ""); >+ type = type.replace(/\s+$/, ""); >+ type = type.replace(/\s*;.*/, ""); I don't know how regexp compilation works, but maybe that's easier in one run: replace(/^\s+|\s*(?:;.*)?$/g, "") Of course that are only nits and not where real time will be spent.
(In reply to comment #4) > Why not |gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false)|? > DOMLinkHandler could be a function or it could implement handleEvent. > It's immutable to prevent others from redefining it and there are already patches to make us listen to DOMLinkRemoved, so I think it's a lot cleaner to just have the individual properties and share the same body for both. > |for each| for arrays is slow. Not my code and really, really negligible for the number of elements that'll typically see. > I don't know how regexp compilation works, but maybe that's easier in one run: > replace(/^\s+|\s*(?:;.*)?$/g, "") Also not mine :) I'd hope that the overhead of creating and compiling three small regexps objects would be greater than that of one larger, global one. I'll test it and replace if that's indeed the case.
Attached patch Patch v2Splinter Review
Updated to better handle some of the quirkier things we'll run into.
Attachment #281971 - Attachment is obsolete: true
Attachment #281978 - Attachment is obsolete: true
Attachment #283126 - Flags: review?(mconnor)
Attachment #281978 - Flags: review?(mconnor)
Comment on attachment 283126 [details] [diff] [review] Patch v2 looks good, please get this landed ASAP (on a quiet tree)
Attachment #283126 - Flags: review?(mconnor)
Attachment #283126 - Flags: review+
Attachment #283126 - Flags: approval1.9+
mozilla/browser/base/content/browser.js 1.857 mozilla/browser/base/content/tabbrowser.xml 1.244 mozilla/browser/base/content/utilityOverlay.js 1.54 mozilla/browser/base/content/pageinfo/feeds.js 1.4 mozilla/browser/base/content/test/Makefile.in 1.5 mozilla/browser/base/content/test/autodiscovery.html 1.1 mozilla/browser/base/content/test/browser_autodiscovery.js 1.1 mozilla/browser/base/content/test/moz.png 1.1 Looks like around a 1% win on Talos' pageset, but there was a regression checked in after this so we'll need a couple more runs to know for sure.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Flags: blocking-firefox3?
Resolution: --- → FIXED
(In reply to comment #5) > (In reply to comment #4) > > Why not |gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false)|? > > DOMLinkHandler could be a function or it could implement handleEvent. > > > It's immutable to prevent others from redefining it and there are already > patches to make us listen to DOMLinkRemoved, so I think it's a lot cleaner to > just have the individual properties and share the same body for both. > I don't follow this comment. What is immutable and how does DOMLinkRemoved prevent us from adding a handleEvent method on DOMLinkHandler which does the right thing depending on the event name? Right now you're creating an unnecessary closure, which wastes some resources (probably not too much in this case), and makes it easier to waste more resources when prepareForStartup gets modified. (The local variables in prepareForStartup only get collected when the window is closed.)
Oh and for DOMLinkRemoved - do you have the bug #? I could only find bug 380639 / bug 396056.
(In reply to comment #9) > (In reply to comment #5) > > (In reply to comment #4) > > > Why not |gBrowser.addEventListener("DOMLinkAdded", DOMLinkHandler, false)|? > > > DOMLinkHandler could be a function or it could implement handleEvent. > > > > > It's immutable to prevent others from redefining it and there are already > > patches to make us listen to DOMLinkRemoved, so I think it's a lot cleaner to > > just have the individual properties and share the same body for both. > > > > I don't follow this comment. Yeah, I didn't really understand that either. -> filed bug 398399.
Depends on: 398399
Comment on attachment 283126 [details] [diff] [review] Patch v2 >+ if (type) >+ aData.type = type; Bah, silly in/out parameter :s
Blocks: FF2SM
No longer blocks: FF2SM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: