Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Is empty functions optimized away whenever know?
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
  6 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
 
idleman  
View profile  
 More options Oct 20 2012, 4:05 pm
From: idleman <evoo...@gmail.com>
Date: Sat, 20 Oct 2012 13:05:04 -0700 (PDT)
Local: Sat, Oct 20 2012 4:05 pm
Subject: Is empty functions optimized away whenever know?

Hi,

Is empty functions in lined whenever the function is know? Example:

function do_nothing() { }

//somewhere later in the code:
var cb = do_nothing;
cb(null, "Will this call be inlined/optimized away?");

Will V8 actually call the function, even if it does nothing? I wonder
because I want to know if it is smarter to create a do_nothing() function
which will be reused over and over again (but not as obvious) or each time
create an empty function { } directly in place and let the V8 more easily
optimize away the call.

Thanks in advance!


 
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.
Vyacheslav Egorov  
View profile  
 More options Oct 21 2012, 10:15 am
From: Vyacheslav Egorov <vego...@chromium.org>
Date: Sun, 21 Oct 2012 16:15:16 +0200
Local: Sun, Oct 21 2012 10:15 am
Subject: Re: [v8-users] Is empty functions optimized away whenever know?

V8 does inline functions at call sites where target is observed to be
always the same. Inclined body is guarded by an identity check against
identity of the call target. If guard fails code is deoptimized.

Thus what matters is whether each call site is monomorphic ( sees the same
function all the time) or megamorphic (sees different functions).

Without seeing complete code it is hard to say whether you will help
inlining by creating a single empty function (inlining definitely will not
happen if you create new functions and send them to a single call site
again and again). But you will definitely save space.

--
Vyacheslav Egorov
 On Oct 20, 2012 10:05 PM, "idleman" <evoo...@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.
idleman  
View profile  
 More options Oct 21 2012, 1:10 pm
From: idleman <evoo...@gmail.com>
Date: Sun, 21 Oct 2012 10:10:53 -0700 (PDT)
Local: Sun, Oct 21 2012 1:10 pm
Subject: Re: [v8-users] Is empty functions optimized away whenever know?

Thanks for your answer!

To make the question some more clear, I invoke huge number of asynchronous
functions, but sometimes I just don´t care about the result, but the
function itself require a callback to pass the result of the operation to.
Would it in those cases be smarter to create a global do_nothing() function
and pass it into all the asynchronous functions where I don´t care about
the result, than on invocation just create a new empty function:

//new empty functions each time
async_http_get("http://statics.com?webpage=abc", function() { });
async_flush(function() { });

//or using a global do_nothing function
function do_nothing() { }

async_http_get("http://statics.com?webpage=abc", do_nothing);
async_flush(do_nothing);

My question regards if V8 would easier optimize away the "callback" call
when using anonymous empty functions or not, because if it does, it would
be worthless to create a global do_nothing on the first place.

But what I understood, V8 does no such optimizations? What would be better
in that case, using a global do_nothing() or not?

Thanks in advance!

Den söndagen den 21:e oktober 2012 kl. 16:15:19 UTC+2 skrev Vyacheslav
Egorov:


 
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.
Michael Schwartz  
View profile  
 More options Oct 21 2012, 1:19 pm
From: Michael Schwartz <myk...@gmail.com>
Date: Sun, 21 Oct 2012 10:19:00 -0700
Subject: Re: [v8-users] Is empty functions optimized away whenever know?

How about:

async_flush(null);

or simler:

async_flush();

On Oct 21, 2012, at 10:10 AM, idleman <evoo...@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.
Vyacheslav Egorov  
View profile  
 More options Oct 21 2012, 1:58 pm
From: Vyacheslav Egorov <vego...@chromium.org>
Date: Sun, 21 Oct 2012 19:58:00 +0200
Subject: Re: [v8-users] Is empty functions optimized away whenever know?

Well if you create a single global function you will at least save memory
and allocation time (as function literal creates a new function  every time
it is executed).

Additionally if you always pass empty function to async_http_get then its
better to create a single function to help inlining as explained in my
previous mail.

Anyway all this matters only on a very hot path.

Vyacheslav Egorov
On Oct 21, 2012 7:10 PM, "idleman" <evoo...@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.
idleman  
View profile  
 More options Oct 21 2012, 2:08 pm
From: idleman <evoo...@gmail.com>
Date: Sun, 21 Oct 2012 11:08:13 -0700 (PDT)
Local: Sun, Oct 21 2012 2:08 pm
Subject: Re: [v8-users] Is empty functions optimized away whenever know?

Thanks, exactly what I wanted to hear. :-)

PS. async_http_get and async_flush was only used as an example, they does
not exist.

Den söndagen den 21:e oktober 2012 kl. 19:58:03 UTC+2 skrev Vyacheslav
Egorov:


 
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 »