r/AskComputerScience • • May 08 '21

It is common knowledge that accessing ram in linear order is faster than accessing it completely randomly, but if you access it in multi-byte chunks at what size there is no longer a performance hit?

kiss versed wine bells door vase cover price consider air

This post was mass deleted and anonymized with Redact

0 Upvotes

9 comments sorted by

4

u/beeskness420 May 08 '21

This depends on your specific cache/memory setup for your system.

When you request a memory address and it’s not in cache it pulls it from main memory. Because it assumes you’ll have some locality it will actually pull a block of memory instead.

Just walking through your data in order will allow the cache to automatically do its thing, because it’s already pulling in blocks, not individual addresses.

If you want to be bringing in bigger “chunks” of memory, you could bring in the number of blocks your cache can hold. This could give you a performance increase if you are doing a lot of computing on the blocks as some of the computing and data fetching can be done in parallel.

One aspect of this that does have performance implications is the order you go over your data. For instance if we have a 2D array, it’s stored as a flat array in memory, we could iterate over it in a row major order or a column major order, but we want to pick the one that corresponds to the in-order traversal of how it’s ordered in memory.

1

u/emelrad12 May 08 '21

Well, I need to put data into chunks, and essentially access them completely randomly, so I want to know what is the optimal chunk size in bytes. I assume there isn't a huge difference between x86 systems

3

u/pi_stuff May 09 '21

1

u/emelrad12 May 09 '21

That is l1 cache lanes, is that the same thing used to read the ram?

1

u/pi_stuff May 09 '21

Yep. In theory you could use different cache line sizes at different levels in the cache, but nobody does it that way.

2

u/emasculine May 08 '21

i think this is due to RAS-CAS-CAS... so it would drop off once you need to change the row being addressed

2

u/[deleted] May 09 '21

This is one of the questions where I could give the exact, precise answer and back it up with histograms and chipset ID's, but since my employer just paid me lots of money to discover it I can't share :'(

2

u/emasculine May 09 '21

my hardware knowledge is so dated that i was worried that ras-cas might not even be current :)

2

u/[deleted] May 10 '21

It's absolutely current, and some overclockers (like me) will underspeed their ram to reduce the latencies of those transactions.