Does changing the type passed to a constructor change a hidden class (and other queries)?

25 views
Skip to first unread message

Wyatt

unread,
Nov 6, 2012, 3:27:16 PM11/6/12
to v8-u...@googlegroups.com
With the follow code one hidden class is created:

function Point(x, y) { 
    this.x = x;
    this.y = y; 
}
var p1 = new Point(11, 22);
var p2 = new Point(33, 44);

Will p2.x="aString"; change its hidden class?

Will p2.x=undefined; change its hidden class?

Will p3= new Point(42,"theAnswer"); create a new hidden class?

I'm inclined to think that the answer is yes for each case..?
Or at least each of these cases seems as if it could not be fully optimized.

Any help is much appreciated!

Vyacheslav Egorov

unread,
Nov 6, 2012, 5:43:07 PM11/6/12
to v8-u...@googlegroups.com
The answer is no for each case.

V8 does not track types of values assigned to a named properties.

Vyacheslav Egorov
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users

Wyatt

unread,
Nov 6, 2012, 6:44:50 PM11/6/12
to v8-u...@googlegroups.com
Interesting! But wouldn't each of these cases nullify any assumptions
made by the type-specializing JIT?

Wyatt

unread,
Nov 6, 2012, 6:48:42 PM11/6/12
to v8-u...@googlegroups.com
Actually these cases would probably just trigger a recompilation
(if the type-specializing JIT was invoked in the first place).

I shall now go re-read your last five blog posts.

Vyacheslav Egorov

unread,
Nov 6, 2012, 6:57:19 PM11/6/12
to v8-u...@googlegroups.com
In V8 currently most assumptions are made and checked at uses, not at
definitions.

Consider for example:

var p = new Point(1, 2);

function add(p) {
return p.x + p.y
}

add(p);

Here the fact that p.x and p.y is numbers is checked at the +
operation. If add is optimized for these assumptions and you pass
point that contains strings in x and y then function add will
deoptimize. But this will happen when you execute add not when you
create point with string values in x and y.
Vyacheslav Egorov


On Tue, Nov 6, 2012 at 3:44 PM, Wyatt <deltaba...@gmail.com> wrote:
> Interesting! But wouldn't each of these cases nullify any assumptions
> made by the type-specializing JIT?
>
Reply all
Reply to author
Forward
0 new messages