Add small codegen improvements for some (TypedArray) self-hosted builtins
Categories
(Core :: JavaScript Engine: JIT, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox66 | --- | fixed |
People
(Reporter: anba, Assigned: anba)
Details
Attachments
(4 files)
|
3.41 KB,
patch
|
jandem
:
review+
|
Details | Diff | Splinter Review |
|
2.07 KB,
patch
|
jandem
:
review+
|
Details | Diff | Splinter Review |
|
2.23 KB,
patch
|
jandem
:
review+
|
Details | Diff | Splinter Review |
|
2.75 KB,
patch
|
jandem
:
review+
|
Details | Diff | Splinter Review |
Test case:
function f() {
// Note: 16 is the maximum size before V8 starts choosing a different allocation strategy.
var ta = new Int32Array(16);
var r = 0
var t = dateNow()
for (var i = 0; i < 4000000; ++i) {
r += ta.slice(0).length;
}
return [dateNow() - t, r];
}
for (var i = 0; i < 5; ++i) print(f());
The patches improve one iteration from the test case from ~600ms to ~500ms for me. For comparison: V8 needs ~370ms.
(Another ~40-50ms can be saved when inlining the @@species getter, but that patch still needs some testing...)
IonGraph shows the following optimization opportunities:
- We can avoid calling
_ConstructorForTypedArray(a non-inlineable native function) inTypedArraySpeciesCreateWithLengthwhen we instead create a customSpeciesConstructorfunction for typed arrays which only calls_ConstructorForTypedArraywhen needed. - Some MMinMax instructions can be folded away, for example
minmax constant43 typedarraylength64whereconstant43is 0 can be removed, because MTypedArrayLength is always >= 0. And there's alsominmax typedarraylength64 typedarraylength64which can be folded totypedarraylength64, becauseMath.[min,max](x, x)is always equal tox.- Folding these instructions allows to fold further instructions later one.
For the test case where slice(0) is called, all minmax and the sub instruction will be removed.
43 constant 0x0
64 typedarraylength phi30
67 minmax [min] constant63 typedarraylength64
72 minmax [min] typedarraylength64 typedarraylength64
75 sub minmax72 minmax67
76 minmax [max] sub75 constant43
101 newtypedarraydynamiclength minmax76
=>
64 typedarraylength phi30
91 newtypedarraydynamiclength typedarraylength64
| Assignee | ||
Comment 1•7 years ago
|
||
This simply copies the existing SpeciesConstructor function from js/src/builtin/Utilities.js and replaces the fallback paths with calls to _ConstructorForTypedArray.
| Assignee | ||
Comment 2•7 years ago
|
||
Adds support to fold Math.[min,max](x, x) to just x and Math.min(typedArrayLength, 0) to 0 and also Math.max(typedArrayLength, 0) to typedArrayLength.
(Isn't it a bit confusing that some of the foldsTo methods have extra type checks for its operands, whereas others simply assume the type policies have already changed the input operands to the correct types. Or is it just me?)
| Assignee | ||
Comment 3•7 years ago
|
||
branchTestClassIsProxy loads the class' flags to check for proxies, but since JSFunction::class_ never has JSCLASS_IS_PROXY set, we can move the proxy check after testing for JSFunction::class_.
| Assignee | ||
Comment 4•7 years ago
|
||
The ValidateTypedArray helper is always called with JSMSG_NON_TYPED_ARRAY_RETURNED, so we might as well remove the parameter and directly bake it into ValidateTypedArray. This change won't have any effect on the generated code, but avoids a stray MConstant(0x1e4) in the final MIR graph, where 0x1e4 is the (current) error code for JSMSG_NON_TYPED_ARRAY_RETURNED.
Comment 5•7 years ago
|
||
Comment 6•7 years ago
|
||
Comment 7•7 years ago
|
||
Comment 8•7 years ago
|
||
| Assignee | ||
Comment 9•7 years ago
|
||
Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=99dd3b557d454857a666e673f8c823727abd8541
Comment 10•7 years ago
|
||
Pushed by nbeleuzu@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/689577cc5af1
Part 1: Add separate SpeciesConstructor for TypedArrays to save a non-inlined runtime call. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/eeba38937ef4
Part 2: Fold MMinMax with MTypedArrayLength and same operands. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/44969cba88bf
Part 3: Test for proxies after testing for JSFunction in IsConstructor codegen. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/1fecb51398bd
Part 4: Remove constant error code for ValidateTypeError helper. r=jandem
Comment 11•7 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/689577cc5af1
https://hg.mozilla.org/mozilla-central/rev/eeba38937ef4
https://hg.mozilla.org/mozilla-central/rev/44969cba88bf
https://hg.mozilla.org/mozilla-central/rev/1fecb51398bd
Description
•