Closed Bug 1391310 Opened 7 years ago Closed 7 years ago

context.wrapPromise is too slow

Categories

(WebExtensions :: General, defect)

defect
Not set
normal

Tracking

(firefox57 fixed)

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: kmag, Assigned: kmag)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The main issue is a bunch of spread args/rest args round trips that the JIT doesn't handle very well, combined with lots of cross-compartment wrapper overhead, and even more X-Ray overhead.
Comment on attachment 8898374 [details]
Bug 1391310: Optimize runSafe/wrapPromise to avoid wrapper/spread arg/rest arg overhead.

https://reviewboard.mozilla.org/r/169748/#review175318

::: toolkit/components/extensions/ExtensionCommon.jsm:252
(Diff revision 1)
>  
>    get principal() {
>      throw new Error("Not implemented");
>    }
>  
> -  runSafe(...args) {
> +  runSafe(callback, ...args) {

nit: it looks like there are maybe 2 other callers of this, so perhaps totally replace all with `applySafe`?

::: toolkit/components/extensions/ExtensionCommon.jsm:268
(Diff revision 1)
>      } else if (!this.active) {
>        Cu.reportError("context.runSafe called while context is inactive");
>      } else {
> -      return runSafeSync(this, ...args);
> +      try {
> +        let {cloneScope} = this;
> +        args = args.map(arg => Cu.cloneInto(arg, cloneScope));

The array will be in a different scope from the arguments.

::: toolkit/components/extensions/ExtensionCommon.jsm:439
(Diff revision 1)
>     *
>     * @returns {Promise|undefined} If callback is null, a promise object
>     *     belonging to the target scope. Otherwise, undefined.
>     */
>    wrapPromise(promise, callback = null) {
> -    let runSafe = this.runSafe.bind(this);
> +    let runSafe = this.applySafe.bind(this);

nit: rename to `applySafe`, the diff below was confusing for a bit (though in part likely because before coffee ;)
Attachment #8898374 - Flags: review?(tomica) → review+
Comment on attachment 8898374 [details]
Bug 1391310: Optimize runSafe/wrapPromise to avoid wrapper/spread arg/rest arg overhead.

https://reviewboard.mozilla.org/r/169748/#review175318

> The array will be in a different scope from the arguments.

That's not a problem. Reflect.apply is in the same scope as the array, so we want the array to be in our scope, and the arguments to be in the callee scope.
Comment on attachment 8898374 [details]
Bug 1391310: Optimize runSafe/wrapPromise to avoid wrapper/spread arg/rest arg overhead.

https://reviewboard.mozilla.org/r/169748/#review175318

> That's not a problem. Reflect.apply is in the same scope as the array, so we want the array to be in our scope, and the arguments to be in the callee scope.

Yeah, that was a comment to myself, figured it out later but missed to drop it. ;)
https://hg.mozilla.org/integration/mozilla-inbound/rev/0e849e7a75c15c43e5b10618a381d79a05a72aaa
Bug 1391310: Optimize runSafe/wrapPromise to avoid wrapper/spread arg/rest arg overhead. r=zombie
https://hg.mozilla.org/mozilla-central/rev/0e849e7a75c1
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Blocks: 1386895
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?(kmaglione+bmo)
Flags: needinfo?(kmaglione+bmo) → 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: