title: Generics using Macro expansion: Why the poor use of Instruction cache?
body: <p>Russ Cox (Go core dev) on his <a href="https://research.swtch.com/generic" rel="nofollow noreferrer">blog</a> on generic implementations mentioned following about the macro expansion(C++) method to implement generics - </p>
  
  <blockquote>
    <p>The individual specializations may be efficient but the program as a
    whole can suffer due to poor use of the instruction cache</p>
  </blockquote>
  
  <p>I have been thinking about this statement for days but fail to understand the reason behind it. Is there any sound reason behind this assumption?</p>
  
  <p>I understand that the instruction cache will not be used well(relatively) if we have -</p>
  
  <ol>
  <li>A poor locality of reference of instructions</li>
  <li>A poor branch prediction.</li>
  </ol>
  
  <p>Does macro expansion causes any of these?</p>
  
  <p><strong>Update</strong>: Similar discussion in <a href="https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4/view#heading=h.6cuzjb7v9wrw" rel="nofollow noreferrer">Go Generic Discussion Summary</a>. Here they generalised the technique used in C++ as <em>Type Specialization</em></p>