Closed Bug 1312411 Opened 8 years ago Closed 8 years ago

Add TypedArrayCompare specialization for ints

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla52
Tracking Status
firefox52 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(1 file)

evilpie suggested this in bug 1293971, comment 3.

And while we're at it, also:
- Add `return 0` to avoid unnecessary swaps in InsertionSort and to ensure the function always returns numbers (https://dxr.mozilla.org/mozilla-central/rev/215f9686117673a2c914ed207bc7da9bb8d741ad/js/src/builtin/TypedArray.js#1100)
- Replace the subtraction with compares, which seems to be faster for doubles (https://dxr.mozilla.org/mozilla-central/rev/215f9686117673a2c914ed207bc7da9bb8d741ad/js/src/builtin/TypedArray.js#1083-1085)
Attached patch bug1312411.patchSplinter Review
Applies on top of bug 1293971.

Comparisons were faster than subtraction for floating point numbers (tested with random numbers generated with |Math.random() * 1000|). Therefore I've changed TypedArrayCompare to use comparisons. For integer values subtraction was faster, so TypedArrayCompareInt still uses |var diff = x - y|.
Attachment #8803949 - Flags: review?(evilpies)
Comment on attachment 8803949 [details] [diff] [review]
bug1312411.patch

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

Awesome, thanks for doing this. Do you have some actual performance numbers?
Attachment #8803949 - Flags: review?(evilpies) → review+
(In reply to Tom Schuster [:evilpie] from comment #2)
> Awesome, thanks for doing this. Do you have some actual performance numbers?

Time in ms for a single execution of `fn`:
  Int16:   1400 ->  445
  Int32:   1440 ->  460
  Float32: 1160 ->  865
  Float64: 1370 -> 1000

```
function fn() {
    var len = 125;
    var ta = new Float64Array(len);
    var t = 0;
    for (var i = 0; i < 100000; ++i) {
        for (var j = 0; j < len; ++j) ta[j] = Math.random() * 1000;
        var d = dateNow();
        ta.sort();
        t += (dateNow() - d);
    }
    return t;
}

// Run it a few times for optimizations to kick in.
for (var i = 0; i < 10; ++i) print(fn());
```
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/7b9c260074e7
Add integer specialization of TypedArrayCompare. r=evilpie
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/7b9c260074e7
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: