Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PSA: Please use XPCOMUtils.defineLazyGlobalGetters rather than Cu.importGlobalProperties

51 views
Skip to first unread message

Kris Maglione

unread,
Jun 7, 2018, 10:09:37 PM6/7/18
to firef...@mozilla.org, dev-pl...@lists.mozilla.org
tl;dr: importGlobalProperties is expensive. If you don't need the imported
properties immediately, please use defineLazyGlobalGetters instead.

Calling importGlobalProperties immediately defines the properties that you're
importing and any prototypes that they require. Aside from CPU overhead, this
also tends to consume a lot of memory, especially for objects with complex
prototypes. And it does this once for every global you call it in. This is
especially a problem for content processes, since we get this memory overhead
in each and every content process (and remember, as a part of Project Fission,
we're aiming to be able to run 100 content processes for ordinary users).

Ordinary WebIDL globals don't really have this problem, since they're already
defined lazily via resolveProperty hooks. In bug 1464548, I added
XPCOMUtils.defineLazyGlobalGetters, which has somewhat similar behavior, and
also has the benefit of always creating the global in the shared JSM module
scope, no matter which global it's called from. Please use that helper from
now on unless you have a very good reason not to.

Thanks.
0 new messages