Closed Bug 1474384 Opened 6 years ago Closed 6 years ago

<xul:browser>.currentURI for lazy browsers is very eager to allocate nsIURI objects

Categories

(Firefox :: Tabbed Browser, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
Firefox 63
Performance Impact high
Tracking Status
firefox63 --- fixed

People

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

References

Details

(Whiteboard: [fxperf:p1])

Attachments

(1 file, 2 obsolete files)

See this profile please:

https://perfht.ml/2KLp2Dp

The culprit is this line: https://searchfox.org/mozilla-central/rev/28daa2806c89684b3dfa4f0b551db1d099dda7c2/browser/base/content/tabbrowser.js#1907

Here, every time browser.currentURI is called, we create a new nsIURI object!  This is very inefficient, as this profile shows.  The majority of the time spent here is doing this work, resulting in UI jank.

The browser session being profiled here contains a large session that has been restored and hence contains a lot of lazy browsers.
Whiteboard: [qf] → [qf][fxperf]
Assignee: nobody → ehsan
Comment on attachment 8990784 [details] [diff] [review]
Memoize the nsIURI object returned from the currentURI getter for lazy <xul:browser> objects

>--- a/browser/base/content/tabbrowser.js
>+++ b/browser/base/content/tabbrowser.js
>@@ -1899,17 +1899,23 @@ window._gBrowser = {
>           getter = () => aTab.hasAttribute("muted");
>           break;
>         case "contentTitle":
>           getter = () => SessionStore.getLazyTabValue(aTab, "title");
>           break;
>         case "currentURI":
>           getter = () => {
>             let url = SessionStore.getLazyTabValue(aTab, "url");
>-            return Services.io.newURI(url);
>+            // Avoid recreating the same nsIURI object over and over again...
>+            if ("_cachedURL" in browser &&
>+                browser._cachedURL &&
>+                browser._cachedURL.spec == url) {
>+              return browser._cachedURL;

The browser._cachedURL null-check makes the |"_cachedURL" in browser| check redundant.

What's the point of the string comparison?

As for the name, I'd prefer _cachedCurrentURI or so.

Please also delete this in _insertBrowser, e.g. after this line: https://searchfox.org/mozilla-central/rev/c579ce13ca7864c5df9711eda730ceb00501aed3/browser/base/content/tabbrowser.js#1990
Attachment #8990784 - Flags: review?(mconley)
Blocks: lazytabs
Priority: -- → P3
Attachment #8990784 - Attachment is obsolete: true
Comment on attachment 8991086 [details] [diff] [review]
Memoize the nsIURI object returned from the currentURI getter for lazy <xul:browser> objects

>--- a/browser/base/content/tabbrowser.js
>+++ b/browser/base/content/tabbrowser.js
>@@ -1899,17 +1899,21 @@ window._gBrowser = {
>           getter = () => aTab.hasAttribute("muted");
>           break;
>         case "contentTitle":
>           getter = () => SessionStore.getLazyTabValue(aTab, "title");
>           break;
>         case "currentURI":
>           getter = () => {
>             let url = SessionStore.getLazyTabValue(aTab, "url");
>-            return Services.io.newURI(url);
>+            // Avoid recreating the same nsIURI object over and over again...
>+            if (browser._cachedURL) {
>+              return browser._cachedURL;
>+            }
>+            return browser._cachedURL = Services.io.newURI(url);

_cachedCurrentURI please

r=me with that change or a compelling reason for preferring _cachedURL as the name
Attachment #8991086 - Flags: review?(dao+bmo) → review+
Whiteboard: [qf][fxperf] → [qf:p1:f64][fxperf:p1]
Attachment #8991086 - Attachment is obsolete: true
Keywords: checkin-needed
Pushed by apavel@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4d3bd7a6b705
Memoize the nsIURI object returned from the currentURI getter for lazy <xul:browser> objects; r=dao
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/4d3bd7a6b705
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 63
Performance Impact: --- → P1
Whiteboard: [qf:p1:f64][fxperf:p1] → [fxperf:p1]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: