Closed Bug 1332610 Opened 7 years ago Closed 7 years ago

Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm

Categories

(Toolkit :: Password Manager, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox52 --- fixed
firefox-esr52 --- fixed
firefox53 --- fixed
firefox54 --- fixed

People

(Reporter: anba, Assigned: MattN)

References

Details

Attachments

(1 file, 1 obsolete file)

LoginManagerContextMenu.jsm creates an Intl.DateTimeFormat object when the module is instantiated [1]. Since LoginManagerContextMenu.jsm is already loaded when starting Firefox, this causes us to initialize the whole JavaScript Intl object and its constructor properties during start-up. This in turn leads to initializing the time zone data from ICU (bug 837961, bug 1303091), which is a bit time-consuming and therefore causes noticeable performance regressions in multiple Talos benchmarks (bug 1314354).

Do you see any problems with changing LoginManagerContextMenu.jsm to create the Intl.DateTimeFormat object only when needed? 

[1] https://dxr.mozilla.org/mozilla-central/rev/aa3e49299a3aa5cb0db570532e3df9e75d30c2d1/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm#22-23
A try push is queued with autoland via RB.
Assignee: nobody → MattN+bmo
Status: NEW → ASSIGNED
Can you look at the perfherder results? I see some wins but also some regressions…
Flags: needinfo?(andrebargull)
Comment on attachment 8829292 [details]
Bug 1332610 - Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm.

https://reviewboard.mozilla.org/r/106402/#review107432

r=me on the code, but I have troubles getting a clear signal out of that perfherder resultset, too.

::: toolkit/components/passwordmgr/LoginManagerContextMenu.jsm:194
(Diff revision 1)
>    return Services.strings.
>           createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
>  });
> +
> +XPCOMUtils.defineLazyGetter(LoginManagerContextMenu, "dateAndTimeFormatter", function() {
> +  return this.dateAndTimeFormatter = new Intl.DateTimeFormat(undefined, {

This works but I haven't seen the "return this.... = ..." style done in lazyGetters so far. Is there a specific reason you're not just returning the new reference directly?

::: toolkit/components/passwordmgr/LoginManagerContextMenu.jsm:197
(Diff revision 1)
> +
> +XPCOMUtils.defineLazyGetter(LoginManagerContextMenu, "dateAndTimeFormatter", function() {
> +  return this.dateAndTimeFormatter = new Intl.DateTimeFormat(undefined, {
> +    day: "numeric",
> +    month: "short",
> +    year: "numeric"

Nit: You could add a trailing comma here.
Attachment #8829292 - Flags: review?(jhofmann) → review+
Comment on attachment 8829465 [details]
Bug 1332610 - Create Intl.DateTimeFormat in LoginManagerContextMenu.jsm lazily.

https://reviewboard.mozilla.org/r/106556/#review107620

This approach is inconsistent with the lazy `_stringBundle` getter so it's why I went with a different approach.
Attachment #8829465 - Flags: review?(MattN+bmo) → review-
Comment on attachment 8829292 [details]
Bug 1332610 - Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm.

https://reviewboard.mozilla.org/r/106402/#review107432

> This works but I haven't seen the "return this.... = ..." style done in lazyGetters so far. Is there a specific reason you're not just returning the new reference directly?

Ugh, yeah, sorry, that's a cut+paste mistake from initially doing the getter+delete approach. I don't think it would have affected the performance though unfortunately. My manual testing showed that what I had actually worked.

> Nit: You could add a trailing comma here.

True, it didn't have it before since it was on one line and I didn't think to check that.
Attachment #8829465 - Attachment is obsolete: true
(In reply to Matthew N. [:MattN] (PM me if requests are blocking you) from comment #5)
> Can you look at the perfherder results? I see some wins but also some
> regressions…

I think this could be just the effect of delaying the time zone data initialization. We probably need to remeasure the performance numbers after bug 1332604 has landed.
Flags: needinfo?(andrebargull)
Are we good to Try remeasuring this now? Looks like bug 1332604 has landed. This bug is blocking an open Talos regression bug going back to Fx52, so it would be good to keep it moving along.
Flags: needinfo?(MattN+bmo)
André, can you look at the perfherder results and decide whether to land. I have no problem landing it even if it doesn't cause perf wins.
Flags: needinfo?(andrebargull)
Forwarding the NI to :jmaher because I'm not sure how to evaluate the perfherder numbers. For example the comparison page claims an 8% regression on tabpaint opt e10s, windows7-32, but when comparing it with the results from the last two weeks [1], I don't think there's any regression for tabpaint.

[1] https://treeherder.mozilla.org/perf.html#/graphs?series=%5Btry,3fa816ffa2efd0725909627d61f6a2a8cad2be5f,1,1%5D&series=%5Bmozilla-inbound,3fa816ffa2efd0725909627d61f6a2a8cad2be5f,0,1%5D&highlightedRevisions=7538950ebcc9&highlightedRevisions=8c8d77bf8160
Flags: needinfo?(andrebargull) → needinfo?(jmaher)
I don't see this causing a real perf regression, just the baseline is hitting the low end of the normal range and the try push hitting the high end of the normal range.

Thanks for checking!
Flags: needinfo?(jmaher)
I thought the point of this bug was to have a perf win to help cancel out bug 1314354 though?
So, I think this change is good to go. Ignoring the tabpaint numbers, the comparison page shows 1-2% improvements for other tests. And combined with the other performance patches, we should see an improvement similar to the results in bug 1314354, comment 14.
Pushed by mozilla@noorenberghe.ca:
https://hg.mozilla.org/integration/autoland/rev/5df20eaa8ef4
Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm. r=johannh
https://hg.mozilla.org/mozilla-central/rev/5df20eaa8ef4
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Please request Aurora/Beta approval on this when you get a chance.
Flags: needinfo?(MattN+bmo)
Flags: needinfo?(MattN+bmo) → needinfo?(andrebargull)
It probably doesn't hurt to backport this change to Aurora/Beta, but I can't give an estimation whether or not we'll see the same Talos changes in Aurora/Beta, because other infrastructural changes to the Intl API aren't present in Aurora/Beta. (I assume the NI was redirected to me to evaluate how useful it is to backport the patch.)
Flags: needinfo?(andrebargull)
Comment on attachment 8829292 [details]
Bug 1332610 - Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm.

Approval Request Comment
[Feature/Bug causing the regression]: bug 837961
[User impact if declined]: perf regression
[Is this code covered by automated tests?]: yes
[Has the fix been verified in Nightly?]: comment 18 suggests a moderate Talos win
[Needs manual test from QE? If yes, steps to reproduce]: no
[List of other uplifts needed for the feature/fix]: none
[Is the change risky?]: no
[Why is the change risky/not risky?]: just delays initializing JavaScript Intl until it's needed
[String changes made/needed]: none
Attachment #8829292 - Flags: approval-mozilla-beta?
Attachment #8829292 - Flags: approval-mozilla-aurora?
Comment on attachment 8829292 [details]
Bug 1332610 - Don't eagerly create Intl.DateTimeFormat in LoginManagerContextMenu.jsm.

perf regression fix, aurora53+, beta52+
Attachment #8829292 - Flags: approval-mozilla-beta?
Attachment #8829292 - Flags: approval-mozilla-beta+
Attachment #8829292 - Flags: approval-mozilla-aurora?
Attachment #8829292 - Flags: approval-mozilla-aurora+
Setting qe-verify- based on Ryan's assessment on manual testing needs (Comment 23) and the fact that this fix has automated coverage.
Flags: qe-verify-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: