On Thu, Jun 12, 2014 at 12:18 PM, Ilya Kantor <[email protected]> wrote:
> Do I get it right that unoptimized code is shared but optimize code is not
> (or shared partially or...)?
>
> If closure is the root of all evil, will it help with sharing if I remove
> the closure completely?
Not quite. What I think Jacob tried to convey is that a closure
basically looks like this:
struct Closure {
Function* function;
Context* context;
};
Each closure has its own context object but they all start out with
the same non-optimized function.
If you have three identical closures and call one of them a million
times, V8 will eventually optimize it and update the closure object to
make it point to the new, optimized function. The other two will
still be pointing to the non-optimized version at that point.
If you then start calling the second closure frequently, the optimizer
is going to discover that it already has an optimized function for
this kind of closure and update the closure object accordingly.
> Like this:
> ```
> function Machine(power) {
>
> this.enable = function() {
> this._enabled = true;
> };
> this.disable = function() {
> this._enabled = false;
> };
> }
>
> var machines = []
> for(var i=0; i<10000; i++) machines.push(new Machine)
> ```
I believe you should unconditionally set `this._enabled = false` (or
true) in the constructor to prevent unnecessary hidden class
transitions.
I'm not 100% sure if it matters in this particular example so someone
please correct me if I'm wrong.
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.