Hi All,<div><br></div><div>    with Marcus chez moi working together on adaptive optimization/speculative inlining Marcus wondered how big the Cog code zone is and how much time goes into reclamation.  Reclamation is the process of throwing away some number of jitted methods to make room for methods that need to be jitted.  Currently Cog&#39;s policy is hard-coded and it always throws away a quarter of the jitted methods, attempting to throw away the least-recenty used, based on a simple 3-bit usage count per method derived from marking methods on the stack and the methods they directly reference.  On my 2.66 GHz Intel Core i7 Mac Book Pro the system seems to compact the code zone once every three or four seconds.  Here is a more precise measurement for recompiling the world in my current development image. </div>
<div><br></div><div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>num compiled methods 93138</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>code size 1048576</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all time (seconds) 48.48</div>
<div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all num compactions 20</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all compaction period 2.42</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>milliseconds per compaction 0.85</div>
<div><span class="Apple-tab-span" style="white-space: pre; ">        </span>percentage of runtime 0.035067</div></div><div><br></div><div>So a few things follow.  A mere megabyte of code seems to be adequate; reclamation rates are low and the latency introduced is of the order of a youngSpace reclamation (I just measured an average of 0.825ms per young space collection in this image); the cost is extremely low, a mere 0.04% of entire execution time.  (Note that the VM is using microsecond resolution times internally and answering totals in milliseconds).  Here are the numbers repeated for a 2 megabyte code zone:</div>
<div><br></div><div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>num compiled methods 93138</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>code size 2097152</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all time (seconds) 54.63</div>
<div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all num compactions 3</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>compile all compaction period 18.21</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>milliseconds per compaction 1.333</div>
<div><span class="Apple-tab-span" style="white-space: pre; ">        </span>percentage of runtime 0.007322</div></div><div><br></div><div>So interestingly the overall runtime is higher, which could be because of poorer cache density due to the larger code zone and hence larger working set, the latency is a little higher (1.333 ms per compaction instead of 0.85) the rate of compactions and total cost is much lower.  It would be interesting to measure costs for a range of code sizes for some realistic applications.  But clearly a one megabyte code cache isn&#39;t that bad a choice.  The code density advantages of a small working set could trump all other considerations.  But of course much more thorough measurements would be required, for example variation in times could be being heavily influenced by the other programs I&#39;ve got open at the moment.</div>
<div><br></div><div>best,</div><div>Eliot</div><div><br></div><div>(| nbefore tbefore nafter tafter size ncm |</div><div>nbefore := Smalltalk vmParameterAt: 62.</div><div>tbefore := Smalltalk vmParameterAt: 63.</div><div>
ms := [Compiler recompileAll] timeToRun.</div><div>nafter := Smalltalk vmParameterAt: 62.</div><div>tafter := Smalltalk vmParameterAt: 63.</div><div>size := Smalltalk vmParameterAt: 46.</div><div>ncm := 0.</div><div>SystemNavigation new allSelect: [:m| ncm := ncm + 1. false].</div>
<div>String new writeStream</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ensureCr;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;num compiled methods &#39;; print: ncm; cr;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;code size &#39;; print: size; cr;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;compile all time (seconds) &#39;; print: (ms / 1000 roundTo: 0.01); cr;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;compile all num compactions &#39;; print: nafter - nbefore; cr;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;compile all compaction period &#39;; print: (ms / 1000 / (nafter - nbefore) roundTo: 0.01); cr;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;milliseconds per compaction &#39;; print: ((tafter - tbefore) asFloat / (nafter - nbefore) roundTo: 0.001); cr;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>nextPutAll: &#39;percentage of runtime &#39;; print: ((tafter - tbefore) * 100.0 / ms roundTo: 0.000001); cr;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>contents)</div>