One thing the author doesn't discuss is that the Boom objects themselves are also in memory, and also have to be accessed -- and can therefore also be visited not in memory order, and cause cache misses.
Changing this to a "structure of arrays" approach, with the x value inline in the array, reduces the runtime by another order of magnitude:
const arr_x = new Array(ROWS * COLS).fill(0);
function doSoA() {
for (let i = 0; i < ROWS; i++) {
for (let j = 0; j < COLS; j++) {
arr_x[i * ROWS + j] = 0;
}
}
}
Started data Local
Finished data locality test run in 0.6168 seconds
Started data Non Local
Finished data locality test run in 2.6442 seconds
Started data Non Local Sorted
Finished data locality test run in 0.7923 seconds
Started data structure-of-arrays
Finished data locality test run in 0.0627 seconds
This is a microbenchmark, so that this with a grain of salt of course.
Changing this to a "structure of arrays" approach, with the x value inline in the array, reduces the runtime by another order of magnitude:
This is a microbenchmark, so that this with a grain of salt of course.