title: GC taking 32% of runtime expected?
body: <p>Currently working on optimizing a library for speed. I've already reduced execution time drastically, using <a href="https://www.jetbrains.com/help/webstorm/v8-cpu-and-memory-profiling.html" rel="nofollow noreferrer">V8 CPU and Memory Profiling</a> through Webstorm. This was achieved mainly by changing the core method from <a href="https://github.com/blackflux/object-scan/pull/366/files#diff-1fdf421c05c1140f6d71444ea2b27638" rel="nofollow noreferrer">recursive to iterative</a>.</p>
  
  <p>Now the self time distribution breaks down as</p>
  
  <p><a href="https://i.stack.imgur.com/kporC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kporC.png" alt="enter image description here"></a></p>
  
  <p>I'm assuming the first entry "node" is timing internal functions calls, which is great. The other entries also make sense. I'm new to Nodejs profiling, but 31.6% for GC seems high, so I've decided to investigate.</p>
  
  <p>I've now created a heap dump through Webstorm, but unfortunately that doesn't give me much information.</p>
  
  <p><a href="https://i.stack.imgur.com/55x9J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/55x9J.png" alt="enter image description here"></a></p>
  
  <p>These seem to be system internal memory references mainly. Stepping through the core <a href="https://github.com/blackflux/object-scan/blob/master/src/index.js#L34" rel="nofollow noreferrer">iteration code logic</a> again, there also don't seem to be a lot of places where memory is explicitly allocated (using <a href="https://stackoverflow.com/questions/18364175/best-practices-for-reducing-garbage-collector-activity-in-javascript#answer-18411275">this</a> as a reference).</p>
  
  <p><strong>Question</strong></p>
  
  <ul>
  <li>Can the GC overhead be reduced?</li>
  <li>Is this amount of allocation just expected here?</li>
  <li>Is it possible to get better memory profiling information?</li>
  </ul>
  
  <p><strong>Setup Instructions</strong></p>
  
  <p>In case someone want's to try debugging this, I'm including setup instructions.</p>
  
  <p>Download or clone <a href="https://github.com/blackflux/object-scan" rel="nofollow noreferrer">object-scan</a> and run </p>
  
  <pre class="lang-sh prettyprint-override"><code>yarn install --frozen-lockfile
  yarn run test-simple --verbose
  </code></pre>
  
  <p>Now create a file <code>test.js</code> in the project root containing <a href="https://github.com/blackflux/object-scan/issues/166#issuecomment-488436070" rel="nofollow noreferrer">this content</a> and run <code>node --trace_gc test.js</code> or run it through Webstorm for advanced profiling.</p>