When we create Sandboxes with wantGlobalProperties, those properties, along with their interfaces and prototypes, are created eagerly, even though they may never be used. For content script sandboxes, the time we spend creating XHR and fetch/Response prototypes seems to add up to something significant, even though they're not likely to ever be used by most content scripts. We should create these objects dynamically, when they're first used, like we do for ordinary DOM windows.
Kris, has this come up in a profile (perhaps in relation to bug 1317681)?
Yes, but the only profile data I currently have for it is from talos, which is a bit flaky. I need to look into it some more with the profiler add-on, but I wanted to make sure I filed a bug before I forgot. But creating content script Sandboxes is definitely more expensive than I'd like (though not as expensive as nuking them), and this is the part of the process that seems to consistently show up in profiles.
OK, looking at a profile from the profiler add-on, loading cnn.com a bunch of times with an extension that loads an empty content script into every frame: https://perfht.ml/2nFUIyd it looks a bit better than it did on talos. We spend a total of about 8ms in CreateSandboxObject, which is about a third of the total time we spend loading content scripts (~half after another set of patches land), but it looks like nearly all of that is in defining global properties.
Thanks for the extra info, Kris. :-)