For eval, two cases need to be distinguished: functions containing an eval statement, and functions defined inside eval'ed code. Consider:
function foo() { /* lots of stuff... */ eval("function bar() { /* lots of stuff... */ }"); /* more stuff... */ } foo(); bar(); In this case, function foo will experience a slowdown because of its eval statement. Back in the Crankshaft days, it wasn't optimizable at all; now with Turbofan, it can be optimized if it's hot, but the presence of eval disables some optimizations (which is unavoidable, due to what eval can do -- an optimizing compiler simply can't eliminate as much stuff as it could without eval). If foo only runs once (as is typical for setup code), then this doesn't matter at all, as functions won't get optimized on their first execution anyway. Function bar, on the other hand, *generally[1]* doesn't care whether it came from an eval statement or someplace else. IIUC this is what you're interested in, and why you're not seeing a performance difference between using eval or a v8::Script. [1] The (obvious?) exception is if the eval statement is executed repeatedly, possibly even with dynamically computed strings, then of course there is parse/compile work going on every time, and depending on what you're doing there the functions generated that way might not live long enough to ever get optimized. So, some performance advice still applies, and will very likely always apply: - don't put eval statements into hot functions - prefer indirect/"global" eval over plain eval - use eval only when you have to (especially for websites: various things like prefetching, streaming, caching work best without eval; if you unnecessarily eval code you'll probably miss out on some benefits. Other embedders of V8 might not care about this.) On Mon, Apr 15, 2019 at 8:03 AM 'Mathias Bynens' via v8-users < v8-users@googlegroups.com> wrote: > The document you linked to is outdated. It was based on Crankshaft which > hasn't been used since V8 v5.9. > > See the first two lines: > > *All this is wrong in TurboFan. (Node 8+)* > *Please do not take anything written here as performance advice, this is > here for historical reasons.* > > On Sun, Apr 14, 2019 at 11:36 PM Al Mo <almos...@gmail.com> wrote: > >> I just found this: >> https://github.com/petkaantonov/bluebird/wiki/Optimization-killers >> >> So that kind of answers my own question. Still, if anyone wants to drop >> its two cents, I'll be glad to read. >> >> Still puzzled why I 'measure' the same performance on both cases. I'm >> doing millions of linear algebra operations. Also compared that to similar >> C and performance is pretty close. If this means they could be even faster >> then wow :D >> >> On Monday, April 15, 2019 at 12:28:03 AM UTC+3, Al Mo wrote: >>> >>> Let's say I have some code and I want to execute it, you could: >>> >>> (a) create a v8::Script, compile it and then run it, >>> >>> OR, >>> >>> (b) send the string to an active v8::Context and call eval(code) from >>> inside. >>> >>> I remember hearing that eval does not optimize code, but in my purely >>> empirical tests both scenarios seem to run code at about the same speed. >>> >>> But still the question is, are there differences in performance between >>> the two approaches? What other things should I expect to be different? >>> >>> >>> -- >> -- >> v8-users mailing list >> v8-users@googlegroups.com >> http://groups.google.com/group/v8-users >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to v8-users+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.