objects vs. arrays

37 views
Skip to first unread message

jasonl...@gmail.com

unread,
Dec 23, 2012, 6:09:48 AM12/23/12
to v8-u...@googlegroups.com
What's the perfrmance difference between creating objects and arrays? Common sense makes me believe that arrays would be quicker because there's less to them internally. Is ths the case? And is it a big enough issue to effect performance when creating complex or large arrays/obects?

I am refering to javascript arrays and objects internally within the v8 api, not within scriptland.

Thanks

Jakob Kummerow

unread,
Dec 23, 2012, 7:12:40 AM12/23/12
to v8-u...@googlegroups.com
On Sun, Dec 23, 2012 at 12:09 PM, <jasonl...@gmail.com> wrote:
What's the perfrmance difference between creating objects and arrays? Common sense makes me believe that arrays would be quicker because there's less to them internally.

Why would there be "less to them internally", whatever that means? As you probably know, in JavaScript, objects and arrays are almost the same, except for arrays' magic "length" property. V8 does have some differing optimization techniques for them, which are mainly based on what they're typically used for (in essence, object = bunch of unrelated properties and methods; array = collection of similar things e.g. numbers). 
 
Is ths the case? And is it a big enough issue to effect performance when creating complex or large arrays/obects?

The only way to be sure whether or not something affects your application is to try both and measure the difference. If you can't measure it, it's not relevant.

Also, complex things in general tend to be expensive. 

I am refering to javascript arrays and objects internally within the v8 api, not within scriptland.

What? A library's API is its interface to the outside world, what does "internally within the API" mean? How can JavaScript objects *not* be in "script land"? 

jasonl...@gmail.com

unread,
Dec 24, 2012, 12:42:08 AM12/24/12
to v8-u...@googlegroups.com
Sorry, I wasn't clear. By 'internally' I'm referring to within the javascript engine - or better yet, within the space that the javascript engine is initialized in. As for arrays/objects this is a reference to their data structure within this system, not as they're represented in a script. By 'less to them internally' I'm referring to the differences in the data structure of an object, and the steps taken when one is created. I'm not exactly sure of what is allocated when a javascript array is created internally within v8, but I will go out on a limb and guess less then that of an object, plus objects must be checked for constructors and so forth when created. v8 probably checks first to see if an object contains methods of it's own before looking for a constructor, but this too is a step not needed with an array.

By API I'm referring to the framework provided by v8 for creating objects within the engine, not within the script. They are not introduced into scriptspace unless returned by the procedure that created them or are somehow otherwise placed somewhere accessible to objects in scriptspace.


>> The only way to be sure whether or not something affects your application is to try both and measure the difference. If you can't measure it, it's not relevant.

Yes, but it's quicker and more sensible to ask those who already know ;) I enjoy experimenting on my free time, but at this point I have 30+ hours into a procedure that converts a hashtable from C into javascript objects and javascript objects into the hashtable structure. I'd rather not write it twice if not needed. And I have to disagree, it is very possible at this level for things that I can't measure to become relevant. The procedure is likely to be called hundreds of times in a minute on largely variyng sets of data.
Reply all
Reply to author
Forward
0 new messages