Add TypedArrayCompare specialization for ints

RESOLVED FIXED in Firefox 52

Status

()

Core
JavaScript: Standard Library
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: anba, Assigned: anba)

Tracking

(Blocks: 1 bug)

Trunk
mozilla52
Points:
---

Firefox Tracking Flags

(firefox52 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

2 years ago
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)
(Assignee)

Comment 1

2 years ago
Created attachment 8803949 [details] [diff] [review]
bug1312411.patch

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+
(Assignee)

Comment 3

2 years ago
(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());
```
(Assignee)

Updated

2 years ago
Keywords: checkin-needed

Comment 4

2 years ago
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/7b9c260074e7
Add integer specialization of TypedArrayCompare. r=evilpie
Keywords: checkin-needed

Comment 5

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/7b9c260074e7
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox52: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in before you can comment on or make changes to this bug.