Hi Ben,

Is that somehow related with "Hidden classes" for objects or that's a 
completely another optimization technique?

среда, 11 июня 2014 г., 0:29:07 UTC+4 пользователь Ben Noordhuis написал:
>
> On Tue, Jun 10, 2014 at 9:58 PM, Ilya Kantor <ili...@gmail.com 
> <javascript:>> wrote: 
> > Hi, 
> > 
> > When I create many objects new Machine like this 
> > ``` 
> > function Machine(power) { 
> >   var enabled = false; 
> > 
> >   this.enable = function() { 
> >     enabled = true; 
> >   }; 
> >   this.disable = function() { 
> >     enabled = false; 
> >   }; 
> > } 
> > 
> > var machines = [] 
> > for(var i=0; i<10000; i++) machines.push(new Machine) 
> > ``` 
> > 
> > ...I see in Chrome Heap Profile that every object has 36 bytes for 
> function 
> > enable/disable. 
> > That is so even if the function code is actually longer. 
> > 
> > Do I get it right that V8 actually creates these functions only ONE time 
> and 
> > uses it for all machines? 
>
> That's correct, there is only one function.  Those 36 byte instances 
> that you're seeing are closure environments for the captured variable. 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to