Closed Bug 506116 Opened 15 years ago Closed 15 years ago

speed up makeURI(str) and use it in browser.js

Categories

(Firefox :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 3.6a1

People

(Reporter: dietrich, Assigned: Natch)

References

Details

(Keywords: perf, Whiteboard: [ts])

Attachments

(1 file, 5 obsolete files)

right now there are of intanciations of ioservice all over the place
Whiteboard: [ts]
We already have makeURI from contentAreaUtils.js used in a few places, but it doesn't keep a reference to the IO service. We should fix that and then convert other places to use it.
Taking. Patch up in a few.
Assignee: nobody → highmind63
Status: NEW → ASSIGNED
Attached patch patch (obsolete) — Splinter Review
So, just adding a variable in an external helper js file seemed wrong to me, so I wrapped it in an object. IMO the whole file should be wrapped in that object, but that requires updating the whole tree and isn't necessary for this bug. I'd be willing to do it though, so feel free to file a bug and assign it to me if there's an interest.

This contains the changes to browser.js and contentAreaUtils.js.
Attachment #390678 - Flags: review?(dietrich)
I don't know whether or not it is recommended practice, but the other callers of makeURI seem to be happy not passing the trailing null parameters as the undefined values will become null when passed on in
> return ContentAreaUtils.ioService.newURI(aURL, aOriginCharset, aBaseURI);
Thanks for the quick patch Natch! I agree w/ comment #4 - change makeURI so that the subsequent arguments are optional, making it more caller-friendly.
Comment on attachment 390678 [details] [diff] [review]
patch

clarified on irc, fixup the function if needed. please fix callers to not pass null arguments where not necessary. r=me otherwise. please get second review from a browser peer and a toolkit peer, as i'm neither. (get gavin to review, and you'll get both!)
Attachment #390678 - Flags: review?(dietrich) → review+
Attachment #390678 - Flags: review?(gavin.sharp)
Attachment #390678 - Flags: review?(neil)
Attachment #390678 - Flags: review?(gavin.sharp)
Attachment #390678 - Flags: review?(dao)
Comment on attachment 390678 [details] [diff] [review]
patch

Actually, I'll try to get two other reviewers seeing as gavin is pretty swamped with reviews.
Attached patch patch ver. 2 (obsolete) — Splinter Review
Silly mistake, could've sworn I had changed it...
Attachment #390678 - Attachment is obsolete: true
Attachment #390971 - Flags: review?(dao)
Attachment #390678 - Flags: review?(neil)
Attachment #390678 - Flags: review?(dao)
Attachment #390971 - Flags: review?(neil)
Comment on attachment 390971 [details] [diff] [review]
patch ver. 2

>diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js

A couple of places you explicitly pass null, null for the last two arguments to makeURI - common practice is to just omit them and let xpconnect do the conversion, but I don't feel strongly about that.

>   _getManifestURI: function(aWindow) {

>-      var ios = Cc["@mozilla.org/network/io-service;1"].
>-                getService(Ci.nsIIOService);
>-
>-      var contentURI = ios.newURI(aWindow.location.href, null, null);
>-      return ios.newURI(attr, aWindow.document.characterSet, contentURI);
>+      var contentURI = makeURI(aWindow.location.href, null, null);
>+      return makeURI(attr, aWindow.document.characterSet, contentURI);

This method should really be using aWindow.document.documentURIObject as the baseURI, rather than creating its own URI. Can do that in a followup, I guess, if you want to avoid scope creeping this patch.

>   // XXX: duplicated in preferences/advanced.js
>   _getOfflineAppUsage: function (host, groups)

Probably worth avoiding this change just to keep these two methods in sync. This isn't a particularly perf-sensitive code path.

>   observe: function (aSubject, aTopic, aState)
>   {

>-        var uri = Cc["@mozilla.org/network/io-service;1"].
>-                  getService(Ci.nsIIOService).
>-                  newURI(aSubject.location.href, null, null);
>+        var uri = makeURI(aSubject.location.href, null, null);

Same here: aSubject.document.documentURIObject.

r=me, but I think the new policy requires sr on this patch...
Attachment #390971 - Flags: review?(neil)
Attachment #390971 - Flags: review?(dao)
Attachment #390971 - Flags: review+
Attached patch comments addressed (obsolete) — Splinter Review
Thanks Gavin. I addressed all the comments, including the change from makeURI to documentURIObject.

I ran all the browser-chrome tests and the mochitest-plain offline tests under dom/ and all is well, so this should be fine.
Attachment #390971 - Attachment is obsolete: true
Attachment #390990 - Flags: superreview?(vladimir)
Comment on attachment 390990 [details] [diff] [review]
comments addressed

Looks great to me.
Attachment #390990 - Flags: superreview?(vladimir) → superreview+
Though I should ask -- why did the io service move to ContentAreaUtils?  That seems odd, especially in light of bug 506111.
This file needs it and it can be used in any file that wants it. Previously this file would call getService every time this function was called. Now there's a smart getter for it, I just figured it wasn't right to declare a global variable in a shared js file. See comment 3.

Thanks.
Keywords: checkin-needed
Summary: add utility function for newURI(str) in browser.js → speed up makeURI(str) and use it in browser.js
http://hg.mozilla.org/mozilla-central/rev/870f451d8385
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 3.6a1
Blocks: 506861
Keywords: perf
Comment on attachment 390990 [details] [diff] [review]
comments addressed

>diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js

>   _getManifestURI: function(aWindow) {

>-    if (!attr) return null;
>-
>-    try {
>-      var ios = Cc["@mozilla.org/network/io-service;1"].
>-                getService(Ci.nsIIOService);
>-
>-      var contentURI = ios.newURI(aWindow.location.href, null, null);
>-      return ios.newURI(attr, aWindow.document.characterSet, contentURI);
>-    } catch (e) {
>-      return null;
>-    }
>+    return attr ? aWindow.document.documentURIObject : null;

This is wrong - you need to use the "attr" value still - the documentURIObject is only useful as the baseURI (i.e. the third argument to makeURI).

I'm surprised we don't have a test that breaks because of this... we really should.
Attachment #390990 - Flags: review-
Backed that out: https://hg.mozilla.org/mozilla-central/rev/4ef37aa4511d
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Blocks: 506111
Comment on attachment 390990 [details] [diff] [review]
comments addressed

>--- a/toolkit/content/contentAreaUtils.js
>+++ b/toolkit/content/contentAreaUtils.js

> function openURL(aURL)
> {
>-  var ios = Components.classes["@mozilla.org/network/io-service;1"]
>-                      .getService(Components.interfaces.nsIIOService);
>-  var uri = ios.newURI(aURL, null, null);
>+  var uri = makeURI(aURL, null, null);

You missed this one when removing the trailing null parameters.
Comment on attachment 390990 [details] [diff] [review]
comments addressed

>--- a/toolkit/content/contentAreaUtils.js
>+++ b/toolkit/content/contentAreaUtils.js

> function openURL(aURL)
> {
>-  var ios = Components.classes["@mozilla.org/network/io-service;1"]
>-                      .getService(Components.interfaces.nsIIOService);
>-  var uri = ios.newURI(aURL, null, null);
>+  var uri = makeURI(aURL, null, null);

ios is still used in that function.
Right, sorry about that. I ran the tests and nothing came up, and I misunderstood what gavin had said earlier, I'll make both changes.

For the openURL issue (that it still uses ios) I'll use ContentAreaUtils.ioService.
Attached patch patch (obsolete) — Splinter Review
OK, all the comments were addressed. Sorry for the confusion, if someone could point me out to how and when _getManifestURI works I'll try to create a test.
Attachment #390990 - Attachment is obsolete: true
Attachment #391098 - Flags: review?(gavin.sharp)
Attachment #391098 - Attachment is patch: true
Attachment #391098 - Attachment mime type: application/octet-stream → text/plain
Status: REOPENED → ASSIGNED
Flags: in-testsuite?
Comment on attachment 391098 [details] [diff] [review]
patch

>diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js

>   _getManifestURI: function(aWindow) {
>     if (!aWindow.document.documentElement) return null;
>     var attr = aWindow.document.documentElement.getAttribute("manifest");
>     if (!attr) return null;
>-
>-    try {
>-      var ios = Cc["@mozilla.org/network/io-service;1"].
>-                getService(Ci.nsIIOService);
>-
>-      var contentURI = ios.newURI(aWindow.location.href, null, null);
>-      return ios.newURI(attr, aWindow.document.characterSet, contentURI);
>-    } catch (e) {
>-      return null;
>-    }
>+    return makeURI(attr,
>+                   aWindow.document.characterSet,
>+                   aWindow.document.documentURIObject);

Don't think you can get rid of the try/catch, since the "attr" may be bogus.

This method only seems to be used in response to "offline-cache-update-completed", which doesn't seem to be covered by existing tests. Perhaps test_offlineNotification.html could be modified to cover that case? I'm not an expert on that offline cache code, so perhaps we should just defer the documentURIObject changes to a followup to reduce the risk/churn here.
Attached patch patch (obsolete) — Splinter Review
Ok, fair enough.
Attachment #391098 - Attachment is obsolete: true
Attachment #391122 - Flags: review?(gavin.sharp)
Attachment #391098 - Flags: review?(gavin.sharp)
Comment on attachment 391122 [details] [diff] [review]
patch

>diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js

>   observe: function (aSubject, aTopic, aState)

>-        var uri = Cc["@mozilla.org/network/io-service;1"].
>-                  getService(Ci.nsIIOService).
>-                  newURI(aSubject.location.href, null, null);
>+        var uri = aSubject.document.documentURIObject;

Defer this change to the followup as well and just use makeURI(aSubject.location.href)?
Attachment #391122 - Flags: review?(gavin.sharp) → review+
Attached patch nit addressedSplinter Review
Does this need re-super-review? Remove checkin-needed if it doesn.
Attachment #391122 - Attachment is obsolete: true
Keywords: checkin-needed
Tests will come in the followup for the two changes skipped in this bug. Those are the only functional changes here.
Flags: in-testsuite? → in-testsuite-
http://hg.mozilla.org/mozilla-central/rev/a7a8c6169d63
Status: ASSIGNED → RESOLVED
Closed: 15 years ago15 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
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: