Open mbebenita opened 9 years ago
We can still use set
w/ subarray
, but on the i16
array.
This is great! However, java/lang/System.arraycopy
needs a similar treatment. In DataInputOutputStreamBench
it is responsible for much of the execution time. I prototyped two cases, and the perf improved considerably form 1067ms to 783ms.
if (i32[srcAddr + J2ME.Constants.OBJ_CLASS_ID_OFFSET >> 2] ===
i32[dstAddr + J2ME.Constants.OBJ_CLASS_ID_OFFSET >> 2]) {
var classId = i32[srcAddr + J2ME.Constants.OBJ_CLASS_ID_OFFSET >> 2];
var classInfo = J2ME.classIdToClassInfoMap[classId];
if (classInfo instanceof J2ME.PrimitiveArrayClassInfo) {
if (classInfo.bytesPerElement === 1) {
var src = (srcAddr + J2ME.Constants.ARRAY_HDR_SIZE) + srcOffset;
var dst = (dstAddr + J2ME.Constants.ARRAY_HDR_SIZE) + dstOffset;
i8.set(i8.subarray(src, src + length), dst);
return;
} else if (classInfo.bytesPerElement === 2) {
var src = (srcAddr + J2ME.Constants.ARRAY_HDR_SIZE >> 1) + srcOffset;
var dst = (dstAddr + J2ME.Constants.ARRAY_HDR_SIZE >> 1) + dstOffset;
i16.set(i16.subarray(src, src + length), dst);
return;
}
}
}
https://github.com/mozilla/pluotsorbet/pull/1801 optimizes System::arraycopy.
1801 was reverted in #1816 for causing a regression.
And re-enabled in #1821.
This is almost done, I want to test one more thing before closing.
We implement unchecked array copies as:
We could implemented it directly as:
This speeds up the following microbenchmark by 2X: