Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although V8 does indeed cache many things, <strike>this isn't one of those cases, as can be demonstrated by the following code</strike>:</p> <pre><code>&gt; function foo(){ this.bar = function(){ return this.x; }; this.x = Math.random(); } &gt; var ary = []; &gt; for(var i=0; i&lt;1000000; i++){ ary.push(new foo()); } </code></pre> <p>the above uses 144MB of memory.</p> <pre><code>&gt; function foo(){ this.x = Math.random(); } &gt; foo.prototype.bar = function(){ return this.x; } &gt; var ary = []; &gt; for(var i=0; i&lt;1000000; i++){ ary.push(new foo()); } </code></pre> <p>And this uses 68MB of memory.</p> <p>Note that the V8 source header at:</p> <p><a href="http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/compilation-cache.h?r=5284" rel="nofollow">http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/compilation-cache.h?r=5284</a></p> <p>Seems to imply that the compilation of said function may indeed be cached :</p> <blockquote> <p>The compilation cache keeps shared function infos for compiled scripts and evals. The shared function infos are looked up using the source string as the key. For regular expressions the compilation data is cached.</p> </blockquote> <p>But the test shows that even if the compilation is compiled, new objects are still created, as if you were not creating new objects you would break JS :)</p> <p><em><strong>EDIT</em></strong></p> <p>A further test:</p> <pre><code>function foo(){ this.bar = function(){ this.x = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'; return this.x; }; this.x = Math.random(); } var ary = []; for(var i=0; i&lt;1000000; i++){ ary.push(new foo()); } </code></pre> <p>Uses 144MB of memory. Due to the fact that I added a 100 char string, if the function itself were not cached, we would be using an extra 100MB or so of memory.</p> <p>So the above indicates that yes, the function itself is cached. But it still needs to be represented by a new object.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload