Closed Bug 1410640 Opened 7 years ago Closed 7 years ago

Allow nursery allocation for arrow functions?

Categories

(Core :: JavaScript: GC, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla58
Tracking Status
firefox58 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

bug 989414 only enabled nursery allocation for normal functions, so currently arrow functions are still always allocated in the tenured heap. Is there any technical limitation which prohibits nursery allocation of arrow functions? And if there's no technical limitation, does it make sense to allow nursery allocation of arrow functions resp. is more useful not to allow nursery allocation of arrow functions?
I haven't looked but don't see why there should be any reason not to do this. Thanks for pointing this out.
Blocks: es6perf
Does this refer to the function closure object itself or allocations that the arrow function performs?
Priority: -- → P2
To the arrow function itself. Specifically I was wondering if we can align the CloneFunctionObjectIfNotSingleton calls in js::Lambda [1] and js::LambdaArrow [2]. [1] https://searchfox.org/mozilla-central/rev/8a6a6bef7c54425970aa4fb039cc6463a19c0b7f/js/src/vm/Interpreter.cpp#4401 [2] https://searchfox.org/mozilla-central/rev/8a6a6bef7c54425970aa4fb039cc6463a19c0b7f/js/src/vm/Interpreter.cpp#4414-4415
Good find, we should fix this. André can you take this? Else I can do it.
Attached patch bug1410640.patchSplinter Review
https://hg.mozilla.org/mozilla-central/rev/8c234572141a2593807d8ff5960f6c7789305da7 only changed js::Lambda(...) to enable nursery allocation of normal functions, so I assume for arrow functions we also just need to adjust js::LambdaArrow(...)? The patch improves this µ-benchmark from 360ms to 20ms for me: var q = 0; var t = dateNow(); for (var i = 0; i < 1000000; ++i) { q += (() => i)(); } print(dateNow() - t, q);
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Attachment #8921411 - Flags: review?(jcoppeard)
Comment on attachment 8921411 [details] [diff] [review] bug1410640.patch Review of attachment 8921411 [details] [diff] [review]: ----------------------------------------------------------------- Great, thanks for fixing this.
Attachment #8921411 - Flags: review?(jcoppeard) → review+
(In reply to André Bargull [:anba] from comment #5) > The patch improves this µ-benchmark from 360ms to 20ms for me: > > var q = 0; > var t = dateNow(); > for (var i = 0; i < 1000000; ++i) { > q += (() => i)(); > } > print(dateNow() - t, q); Is this with Ion disabled? Ion should do nursery allocation inline in CodeGenerator::visitLambdaArrow so I wonder if that's not working...
Flags: needinfo?(andrebargull)
(In reply to Jan de Mooij [:jandem] from comment #7) > Is this with Ion disabled? Ion should do nursery allocation inline in > CodeGenerator::visitLambdaArrow so I wonder if that's not working... Oh maybe we fill up the nursery and then keep calling LambdaArrow OOL without collecting the nursery?
The actual test case I used was: ``` function f() { var q = 0; var t = dateNow(); for (var i = 0; i < 1000000; ++i) { q += (() => i)(); } return [dateNow() - t, q]; } for (var i = 0; i < 10; ++i) print(f()); ``` Running only the function content of |f| in global scope is already fast without this patch: ``` var q = 0; var t = dateNow(); for (var i = 0; i < 1000000; ++i) { q += (() => i)(); } print(dateNow() - t, q); ``` So there seems to be a difference whether or not the benchmark code is run within another function?
Flags: needinfo?(andrebargull)
(In reply to André Bargull [:anba] from comment #9) > So there seems to be a difference whether or not the benchmark code is run > within another function? When we run it in the global scope, |i| is a global name and we can optimize away the arrow allocation. When the code is in a function, we have to get |i| from the arrow's environment chain and we don't optimize away the arrow allocation.
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/1f17f122eb7c Enable nursery allocation of arrow functions. r=jonco
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: