title: What's the (hidden) cost of Scala's lazy val?
body: <p>One handy feature of Scala is <code>lazy val</code>, where the evaluation of a <code>val</code> is delayed until it's necessary (at first access).</p>
  
  <p>Of course, a <code>lazy val</code> must have some overhead - somewhere Scala must keep track of whether the value has already been evaluated and the evaluation must be synchronized, because multiple threads might try to access the value for the first time at the same time.</p>
  
  <p>What exactly is the cost of a <code>lazy val</code> - is there a hidden boolean flag associated with a <code>lazy val</code> to keep track if it has been evaluated or not, what exactly is synchronized and are there any more costs?</p>
  
  <p>In addition, suppose I do this:</p>
  
  <pre><code>class Something {
      lazy val (x, y) = { ... }
  }
  </code></pre>
  
  <p>Is this the same as having two separate <code>lazy val</code>s <code>x</code> and <code>y</code> or do I get the overhead only once, for the pair <code>(x, y)</code>?</p>