Hacker News new | past | comments | ask | show | jobs | submit login

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.



Did the same thing in a game I'm working on, although it's in the backend.

Needed to store millions of routes that had a list of step objects.

Reduced memory usage by an order of magnitude by making the route a list of numbers, since you get rid of all the 8 byte pointers.

https://blog.winricklabs.com/(02-17-2020)---efficient-data-s...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: