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" <[email protected]> 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 > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
