[v8-users] are closures optimized?

100 views
Skip to first unread message

fastduck8000

unread,
May 24, 2010, 3:45:59 AM5/24/10
to v8-users
Hi,

I was looking around for a JavaScript optimization guide for V8 but
couldn't find one. Perhaps I'll contribute a tuning guide once I'm
more familiar with V8.

At any rate, the question that brought me to the discussion group
today -- my intuition is that I should avoid relying on data bundled
up in closures, but is that necessarily true in V8? Are closure
variables somehow packaged into the hidden classes?

Cheers,
-Clifford

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

Erik Corry

unread,
May 25, 2010, 9:34:30 AM5/25/10
to v8-u...@googlegroups.com
Den 24. maj 2010 09.45 skrev fastduck8000 <fastdu...@gmail.com>:
Hi,

I was looking around for a JavaScript optimization guide for V8 but
couldn't find one. Perhaps I'll contribute a tuning guide once I'm
more familiar with V8.

At any rate, the question that brought me to the discussion group
today -- my intuition is that I should avoid relying on data bundled
up in closures, but is that necessarily true in V8? Are closure
variables somehow packaged into the hidden classes?

The closure variables are bundled into on-heap objects.  Since we can statically know a lot about them they are not much like the hidden classes.  That is, they are generally more efficient than the hidden classes.  Note two things though:

* Using 'eval' and 'with' makes closure-accessed variables (and globals like 'Math') very slow since now there is no static analysis available.
* Some of the tricks that Douglas Crockford is fond of ("private variables with closures") will attach a flock of little closure objects to every JS object.  This is going to slow down allocation and bloat their size.
* There's no substitute for benchmarking.  With a language as tricky as JS it's easy to hit some special case that isn't optimized and it's difficult to say anything as general as "it's optimized" or "it's not optimized".
 

Cheers,
-Clifford

--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
Reply all
Reply to author
Forward
0 new messages