Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In <em>example 1</em>, CPU first needs to access the pointer itself, then the actual object.</p> <ul> <li>Pointer is on the stack which gives it a good chance it is already in data cache due good locality with other variables on the stack. It might even be in register.</li> <li>It is unusual for the object to be on the same stack frame as pointer - it is either on the heap (on "random" location) or on a shallower stack frame, and there is a possibility it is no longer in d-cache so you are more likely to pay memory latency penalty.</li> </ul> <p>In <em>example 2</em>, CPU can access the object directly, which is on the stack so it has a good chance it is already cached due good locality with to other variables on the stack.</p> <p>All the memory locations accessed will end-up in d-cache until replaced by more recently accessed locations. How exactly is d-cache maintained and synchronized between different cores in multi-core CPU is implementation detail of a particular CPU and involves "cache lines" (typically 64-bit blocks that are "units" of caching) and various cache coherence protocols.</p> <p>That being said, you should be aware of a serious degradation of performance in multi-threaded environment that may be consequence of these implementation details, called <a href="http://drdobbs.com/go-parallel/article/showArticle.jhtml?articleID=217500206" rel="nofollow">false sharing</a>.</p> <p>Generally speaking, chasing pointers is slower than just accessing memory linearly, because it has worse locality (so caches are less effective) and worse predictability (so CPU cannot utilize prefetching effectively).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload