Closed Bug 1369508 Opened 3 years ago Closed 2 years ago

Optimize calls to nsUXThemeData::InitTitlebarInfo()


(Core :: Widget: Win32, enhancement, P1)




Tracking Status
firefox56 --- fixed


(Reporter: jimm, Assigned: jwatt)



(Whiteboard: tpi:+, [qf:p1])


(1 file, 1 obsolete file)

Optimize calls to nsUXThemeData::InitTitlebarInfo(). See bug 1366874.
Priority: -- → P1
Whiteboard: tpi:+, [qf]
Whiteboard: tpi:+, [qf] → tpi:+, [qf:p1]
Assignee: nobody → jwatt
Quoting from that bug:

Finally we have 88ms spent in nsUXThemeData::InitTitlebarInfo() calling GetSystemMetrics. This seems to be to get data that will be overwritten very soon when the first actual browser window will be opened, with a call to nsUXThemeData::UpdateTitlebarInfo (that spends another 12ms in NtUserGetWindowCompositionAttribute). Could we initialize this placeholder data lazily so that we don't pay this cost if the data isn't going to be used?
We get these dimensions when hitting the cases such as NS_THEME_WINDOW_BUTTON_MINIMIZE in nsNativeThemeWin::GetMinimumWidgetSize due to the use of |-moz-appearance: -moz-window-button-minimize;| etc. in browser/themes/windows/browser.css. Additionally we get the button box size (the button box wraps the buttons) when painting when nsLayoutUtils::PaintFrame calls nsWindow::UpdateOpaqueRegion.
The IsWin8OrLater() check and early return in nsUXThemeData::UpdateTitlebarInfo implies that we only sometimes need values for the buttons since that check makes us return early just after setting the button box dimensions, but before the button dimensions are set further down that function.

That indeed seems to be the case on my pretty much vanilla Win10 machine where the only dimensions that were set during window construction were the button box dimensions, and the only dimensions that seemed to be read were also the button box dimensions. It was therefore necessary to separated the initialization of the button and button box sizes so that fetching the button box size didn't require initializing the other sizes (and therefore making the slow GetSystemMetrics calls).
Attached patch patch (obsolete) — Splinter Review
Attachment #8878847 - Flags: review?(jmathies)

We get 99% of the way through our crashtests before we fail the MOZ_ASSERT_UNREACHABLE assert running:

Basically the issue is that arbitrary content is allowed to use |-moz-appearance:-moz-window-button-close;| etc. regardless of whether the Windows configurations would normally require us to fetch those metrics for our UI elements or not. It looks like I'll need to change the MOZ_ASSERT_UNREACHABLE to an NS_WARNING which is unfortunate. :/
Attachment #8878847 - Attachment is obsolete: true
Attachment #8878847 - Flags: review?(jmathies)
Attachment #8878877 - Flags: review?(jmathies)
(In reply to Jonathan Watt [:jwatt] from comment #4)
> arbitrary content is allowed to use
> |-moz-appearance:-moz-window-button-close;|

Is this intentional or a bug?

I can't think of a legitimate reason for a web page to use this, and it seems like it would help fingerprinters.
I believe it's a limitation of our style system. We have the ability to restrict certain properties to chrome, but not property values as far as I know.
Flags: needinfo?(cam)
We don't have a simple way to do this (by adding a flag somewhere), but we could give -moz-appearance its own nsCSSParser parsing function.  In there we can check ChromeRulesEnabled() when parsing certain values, which would restrict style sheets in content documents from settings those values.
Flags: needinfo?(cam)
Thanks, Cameron. Definitely something for a separate bug then.
Just FYI, we will have to refresh metrics on DPI change when we make use of per-DPI metrics that Creators Update introduced.
Best to file a bug for that since that wouldn't be part of this bug.
Comment on attachment 8878877 [details] [diff] [review]

Review of attachment 8878877 [details] [diff] [review]:

lgtm. I tested this on win7/classic and basic - no issues. great!
Attachment #8878877 - Flags: review?(jmathies) → review+
Pushed by
Avoid slow and unnecessary GetSystemMetrics calls for Window's command buttons during startup. r=jimm
Juggling patches between machines I somehow managed to land the old version of the patch with the MOZ_ASSERT_UNREACHABLE in it. That fails running the headless tests in addition to the crashtest that I noted in comment 4, but we don't yet run the headless tests (MnH) on Try runs it seems. I'll land again with the new version of the patch.
Flags: needinfo?(jwatt)
Pushed by
Avoid slow and unnecessary GetSystemMetrics calls for Window's command buttons during startup. r=jimm
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.