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:
> 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" <evo...@gmail.com <javascript:>> wrote:
>> 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:
>>> 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" <evo...@gmail.com> wrote:
>>>> 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!
>>>> --
>>>> v8-users mailing list
>>>> v8-u...@googlegroups.com
>>>> http://groups.google.com/**group/v8-users<http://groups.google.com/group/v8-users>
>>> --
>> v8-users mailing list
>> v8-u...@googlegroups.com <javascript:>
>> http://groups.google.com/group/v8-users