title: Do Go implementations store the length of a map?
body: <p>Does a <code>map</code> have its length stored somewhere or is it calculated each time we call <code>len(my_map)</code>?</p>
  
  <p>The language spec shows this for maps, which doesn't really help:</p>
  
  <blockquote>
    <p>The number of <code>map</code> elements is called its length. For a map <code>m</code>, it can be discovered using the built-in function <code>len</code> and may change during execution. Elements may be added during execution using assignments and retrieved with index expressions; they may be removed with the delete built-in function. </p>
  </blockquote>
  
  <p>Under the "Length and capacity" section we see this:</p>
  
  <blockquote>
    <p>The expression <code>len(s)</code> is constant if <code>s</code> is a <code>string</code> constant. The expressions <code>len(s)</code> and <code>cap(s)</code> are constants if the type of <code>s</code> is an <code>array</code> or <code>pointer</code> to an <code>array</code> and the expression <code>s</code> does not contain channel receives or (non-constant) function calls; in this case <code>s</code> is not evaluated. Otherwise, invocations of <code>len</code> and <code>cap</code> are not constant and <code>s</code> is evaluated. </p>
  </blockquote>
  
  <p>So it tells us that <code>s</code> isn't constant and is evaluated but it doesn't state if it's looked up as a stored value like they do with the <code>slice</code> type.</p>