Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
V8 Optimizations?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
blackdog  
View profile  
 More options Feb 3 2010, 8:41 am
From: blackdog <blackdo...@gmail.com>
Date: Wed, 3 Feb 2010 05:41:10 -0800 (PST)
Local: Wed, Feb 3 2010 8:41 am
Subject: V8 Optimizations?

Hi,

I was wondering if there were any javascript idioms that v8 can
optimise better than others.

For example, i imagine that having "classes" which don't add/delete
fields are probably better, due to v8's hidden classes.
Also, i believe concatenating strings with += is actually very quick
in v8 and one doesn't need to add to, and then join an array.

I think it would be good to have a list best practices to allow
javascript generation programs to know how best to take advantage V8.

bd


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Corry  
View profile  
 More options Feb 3 2010, 8:43 am
From: Erik Corry <erik.co...@gmail.com>
Date: Wed, 3 Feb 2010 14:43:54 +0100
Local: Wed, Feb 3 2010 8:43 am
Subject: Re: [v8-users] V8 Optimizations?
2010/2/3 blackdog <blackdo...@gmail.com>:

> Hi,

> I was wondering if there were any javascript idioms that v8 can
> optimise better than others.

> For example, i imagine that having "classes" which don't add/delete
> fields are probably better, due to v8's hidden classes.
> Also, i believe concatenating strings with += is actually very quick
> in v8 and one doesn't need to add to, and then join an array.

> I think it would be good to have a list best practices to allow
> javascript generation programs to know how best to take advantage V8.

I agree we should have this.

In the mean time "Don't use the 'with' keyword" is the short version.

--
Erik Corry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Strout  
View profile  
 More options Feb 3 2010, 9:17 am
From: Joe Strout <j...@strout.net>
Date: Wed, 03 Feb 2010 07:17:20 -0700
Local: Wed, Feb 3 2010 9:17 am
Subject: Re: [v8-users] V8 Optimizations?

blackdog wrote:
> Also, i believe concatenating strings with += is actually very quick
> in v8 and one doesn't need to add to, and then join an array.

I'd be very surprised and disappointed in 'join' if it is not
dramatically faster than repeatedly using += in a loop.  Join can
calculate the total string length, and allocate and copy just once.
There's no way += can do that.

Best,
- Joe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Corry  
View profile  
 More options Feb 3 2010, 9:35 am
From: Erik Corry <erik.co...@gmail.com>
Date: Wed, 3 Feb 2010 15:35:26 +0100
Local: Wed, Feb 3 2010 9:35 am
Subject: Re: [v8-users] V8 Optimizations?
2010/2/3 Joe Strout <j...@strout.net>:

> blackdog wrote:

>> Also, i believe concatenating strings with += is actually very quick
>> in v8 and one doesn't need to add to, and then join an array.

> I'd be very surprised and disappointed in 'join' if it is not dramatically
> faster than repeatedly using += in a loop.  Join can calculate the total
> string length, and allocate and copy just once. There's no way += can do
> that.

When you do += in V8 you create a ConsString, which is a tree node
that takes up 20 bytes on 32 bit or 32 bytes on 64 bit.  This is a
relatively fast operation.  The first time you use the string for
things other than consing up results it is converted into a flat
string in much the same way as join would do it.  The ConsString nodes
become garbage which we can collect quite quickly.  Join is subject to
some pretty arcane specifications about how it has to work (eg on
sparse arrays) so that's not a completely trivial operation.

I don't actually know what is faster.  Benchmarks are probably in
order if anyone has time.  Be sure to use a very new V8 version since
there's some recent work in that area and report whether you are on 32
or 64 bit.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Strout  
View profile  
 More options Feb 3 2010, 10:58 am
From: Joe Strout <j...@strout.net>
Date: Wed, 03 Feb 2010 08:58:06 -0700
Local: Wed, Feb 3 2010 10:58 am
Subject: Re: [v8-users] V8 Optimizations?

Erik Corry wrote:
> When you do += in V8 you create a ConsString, which is a tree node
> that takes up 20 bytes on 32 bit or 32 bytes on 64 bit.  This is a
> relatively fast operation.  The first time you use the string for
> things other than consing up results it is converted into a flat
> string in much the same way as join would do it.

Well now THAT is really cool.

> I don't actually know what is faster.  Benchmarks are probably in
> order if anyone has time.

Agreed; intuition about performance is often wrong.

Best,
- Joe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
blackdog  
View profile  
 More options Feb 3 2010, 11:43 am
From: blackdog <blackdo...@gmail.com>
Date: Wed, 3 Feb 2010 08:43:36 -0800 (PST)
Local: Wed, Feb 3 2010 11:43 am
Subject: Re: V8 Optimizations?
someone on #node.js did a test, if i remember correctly += was quicker

On Feb 3, 12:58 pm, Joe Strout <j...@strout.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kiswono Prayogo  
View profile  
 More options Feb 3 2010, 6:51 pm
From: Kiswono Prayogo <kisw...@gmail.com>
Date: Thu, 4 Feb 2010 06:51:26 +0700
Local: Wed, Feb 3 2010 6:51 pm
Subject: Re: [v8-users] Re: V8 Optimizations?
yes, i have tried it too.. ''+=any faster than [any].join('')
on simple operations any+any+any faster than [any,any,any].join('')

--
Regards,
Kiswono P
GB


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Søren Gjesse  
View profile  
 More options Feb 4 2010, 2:18 am
From: Søren Gjesse <sgje...@chromium.org>
Date: Thu, 4 Feb 2010 08:18:40 +0100
Local: Thurs, Feb 4 2010 2:18 am
Subject: Re: [v8-users] Re: V8 Optimizations?

When comparing += and Array.join for building a string it might give a more
precise picture of the actual cost of building a string if the constructed
string is being used afterwards. E.g. include the time used to run a simple
RegExp on the string. The string tree built using += will most likely need
to be converted into a flat string before complex operations (like RegExp)
can be performed on it.

Regards,
Søren


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kung fu tzu  
View profile  
 More options Feb 8 2010, 11:44 am
From: Kung fu tzu <goj...@gmail.com>
Date: Mon, 8 Feb 2010 08:44:15 -0800 (PST)
Local: Mon, Feb 8 2010 11:44 am
Subject: Re: V8 Optimizations?
Am made a simple benchmark. It can be run in all modern browsers to
test them for ConsString support or its analog.

http://lib.programica.ru/lib/tests/benchmarks/cons-string-vs-array-jo...

On Feb 4, 2:51 am, Kiswono Prayogo <kisw...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »