Closed Bug 1461130 Opened 7 years ago Closed 7 years ago

windows.getAll converts all windows even if they don't match windowTypes

Categories

(WebExtensions :: Frontend, enhancement)

enhancement
Not set
normal

Tracking

(firefox62 fixed)

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: Oriol, Assigned: Oriol)

Details

Attachments

(1 file)

https://searchfox.org/mozilla-central/rev/babf96cf0c37b608e9663e2af73a4d21819c4af1/browser/components/extensions/parent/ext-windows.js#118-119 let windows = Array.from(windowManager.getAll(), win => win.convert(getInfo)) .filter(typeFilter); Say that I have 1000 open normal windows, and I run this code: browser.windows.getAll({windowTypes: ["popup"]}) Then the code above will convert all these windows, even if they will be filtered out. This is useless expensive work. Only windows that match should be converted.
It seems that "normal" and "popup" are the only possible window types on Firefox, so I guess that another optimization would be not iterating windows at all if windowTypes doesn't contain any of these. But not sure if it's worth.
I also added that, if windowTypes includes both "normal" and "popup", all windows will match, so there is no need to actually check. This avoids an extra call of the type getter.
Comment on attachment 8975286 [details] Bug 1461130 - Don't convert filtered out windows in windows.getAll https://reviewboard.mozilla.org/r/243612/#review249744 ISTM this would be simpler to just fix the array building to only convert matched windows. return Array.from(windowManager.getAll()).filter(typeFilter).map(win => win.convert(getInfo)); Are there adequate tests covering this change?
Attachment #8975286 - Flags: review?(mixedpuppy)
This seems a proper test: https://searchfox.org/mozilla-central/rev/2b9779c59390ecc47be7a70d99753653d8eb5afc/browser/components/extensions/test/browser/browser_ext_windows.js#25,28,33,40 I was trying to optimize other things, but OK, I will revert to my first patch. It behaves like your code but without creating intermediate arrays.
Comment on attachment 8975286 [details] Bug 1461130 - Don't convert filtered out windows in windows.getAll https://reviewboard.mozilla.org/r/243612/#review249940
Attachment #8975286 - Flags: review?(mixedpuppy) → review+
Keywords: checkin-needed
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/autoland/rev/cb2a199d50d1 Don't convert filtered out windows in windows.getAll r=mixedpuppy
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Is manual testing required on this bug? If Yes, please provide some STR and the proper webextension(if required), if No set the “qe-verify-“ flag.
Flags: needinfo?(oriol-bugzilla)
No change in behavior, just avoiding useless work.
Flags: needinfo?(oriol-bugzilla) → qe-verify-
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: