Closed Bug 1420400 Opened 7 years ago Closed 7 years ago

Optimize Reflect.get

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 2 open bugs)

Details

Attachments

(1 file)

Attached patch PatchSplinter Review
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)
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+
Blocks: es6perf
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
Blocks: 1426796
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: