Optimize Reflect.get

RESOLVED FIXED in Firefox 59

Status

()

Core
JavaScript Engine
RESOLVED FIXED
2 months ago
14 days ago

People

(Reporter: jandem, Assigned: jandem)

Tracking

(Blocks: 2 bugs)

unspecified
mozilla59
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox59 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

2 months ago
Created attachment 8931657 [details] [diff] [review]
Patch

One of the tests in V8's Web Tooling benchmark spends a bunch of time under Reflect.get. Our C++ implementation of that just does a GetProperty and that's slow.

The attached patch self-hosts Reflect.get. If we don't have a receiver, or, receiver === target, we do a JSOP_GETELEM. If we have a receiver we call an intrinsic that we compile to JSOP_GETELEM_SUPER in the bytecode emitter.

For the micro-benchmark below I get:

No receiver:

before: 280 ms
after:   55 ms
d8:      88 ms

When passing |this| as receiver argument:

before:  297 ms
after:    55 ms
d8:      393 ms

We're still slow when passing a primitive receiver argument, due to [0], but that should be fixable. Also, the Reflect.get calls I see in real-world code usually don't pass a receiver argument.

function f() {
    var o = {x: 1};
    var t = new Date;
    for (var i = 0; i < 10000000; i++) {
        o.x = Reflect.get(o, "x") + 1;
    }
    print(new Date - t);
    print(o.x);
}
f();

[0] https://searchfox.org/mozilla-central/rev/a5d613086ab4d0578510aabe8653e58dc8d7e3e2/js/src/jit/CacheIR.cpp#164-168
Attachment #8931657 - Flags: review?(andrebargull)
(Assignee)

Comment 1

2 months ago
Comment on attachment 8931657 [details] [diff] [review]
Patch

Review of attachment 8931657 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/builtin/Reflect.js
@@ +147,5 @@
> +
> +    // Step 3 (reordered).
> +    if (arguments.length > 2) {
> +	var receiver = arguments[2];
> +	if (receiver !== target) {

I think I'll just remove this check. It simplifies the code a bit and having it doesn't help perf in any cases I tried.
Comment on attachment 8931657 [details] [diff] [review]
Patch

Review of attachment 8931657 [details] [diff] [review]:
-----------------------------------------------------------------

Looks great. Thanks!
Attachment #8931657 - Flags: review?(andrebargull) → review+

Comment 3

2 months ago
Pushed by jandemooij@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/4e5334ede43d
Optimize/self-host Reflect.get. r=anba

Updated

2 months ago
Blocks: 1307395

Comment 4

2 months ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/4e5334ede43d
Status: ASSIGNED → RESOLVED
Last Resolved: 2 months ago
status-firefox59: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
(Assignee)

Updated

14 days ago
Blocks: 1426796
You need to log in before you can comment on or make changes to this bug.