Closed Bug 1518101 Opened 10 months ago Closed 10 months ago

Add Nursery::allocateZeroedBuffer for inlined TypedArray construction

Categories

(Core :: JavaScript: GC, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

AllocateObjectBufferWithInit in the inlined TypedArray construction path is currently using malloc followed by memset to create zero-initialized memory for the TypedArray. This leads to sadness when doing µ-benchmarks for TypedArray construction performance, because memset touches every page of the allocated memory, which means the benchmark easily ends up allocating the complete system memory and we soon are measuring how fast the system can perform swap.

In numbers:
The following µ-benchmark reports about four seconds in the "total" count and effectively uses ~8GB memory on my system. When using calloc the "total" count is ~30ms and the memory usage is basically zero.

---
function f() {
    var r = 0;
    var t = dateNow();
    for (var i = 0; i < 2000; ++i) {
        var ta = new Int32Array(265000 + (i & 0x1));
        r += ta.length;
    }
    return [dateNow() - t, r];
}

var t = dateNow()
for (var i = 0; i < 5; ++i) print(f());
print("total:", (dateNow() - t));
---
Attached patch bug1518101.patchSplinter Review
Adds Nursery::allocateZeroedBuffer, which almost the same as Nursery::allocateBuffer, except calloc instead of malloc is used.
Attachment #9034717 - Flags: review?(jcoppeard)
Comment on attachment 9034717 [details] [diff] [review]
bug1518101.patch

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

Great, thanks for fixing.
Attachment #9034717 - Flags: review?(jcoppeard) → review+

Pushed by ccoroiu@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/19051af76b77
Use calloc instead of malloc followed by memset for inlined TypedArray data allocation. r=jonco

Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
You need to log in before you can comment on or make changes to this bug.