Message from discussion
De-optimization of hot function when constructor adds methods directly to object
Received: by 10.52.179.69 with SMTP id de5mr3306425vdc.7.1342659878001;
Wed, 18 Jul 2012 18:04:38 -0700 (PDT)
X-BeenThere: v8-users@googlegroups.com
Received: by 10.220.115.146 with SMTP id i18ls1554954vcq.0.gmail; Wed, 18 Jul
2012 18:04:36 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.52.34.9 with SMTP id v9mr483774vdi.9.1342659876111; Wed, 18
Jul 2012 18:04:36 -0700 (PDT)
Authentication-Results: ls.google.com; spf=pass (google.com: domain of
jmer...@jmerlin.net designates internal as permitted sender)
smtp.mail=jmer...@jmerlin.net; dkim=pass
header...@jmerlin.net
Received: by b1g2000vbb.googlegroups.com with HTTP; Wed, 18 Jul 2012 18:04:35
-0700 (PDT)
Date: Wed, 18 Jul 2012 18:04:35 -0700 (PDT)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)
AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11,gzip(gfe)
Message-ID: <80c7dd92-ffd8-4389-b5cf-a74cb5c99096@b1g2000vbb.googlegroups.com>
Subject: De-optimization of hot function when constructor adds methods
directly to object
From: jMerliN <jmer...@jmerlin.net>
To: v8-users <v8-users@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
So I can't get my head around why this happens (I haven't dug through
v8's code to try to figure it out either), but this is really
inconsistent to me with how v8 constructs hidden classes in general.
The following is running in Node.js v0.8.2 (V8 v3.11.10.12).
Here's the code:
http://pastebin.com/2gKWrfHp
Here's the output, and the deopt trace:
http://pastebin.com/WerQuGLZ
Calling Foo.prototype.runTest with any Foo object results in similar
performance (unless you change the hidden class, as expected). Bar
expectedly deoptimizes because abc is stored on the proto and isn't
actually on the constructed object until the first call, causing the
optimized function (once it gets hot, which is after the object has
changed hidden class) to bailout on the next attempt with a new Bar
object.
It gets weird with Foobar. test is added directly to the object, the
only difference is that this is a function, not a primitive, but it
seems like the hidden classes of objects from Foobar's constructor
should be the same. The first run is performant, equivalent to Foo
(expected). Though running the test again with a new Foobar
deoptimizes it. I can't at all understand why.
Thanks,