Are functions which defined using eval or new Function() optimized?

32 views
Skip to first unread message

Koray

unread,
Mar 1, 2018, 11:27:23 AM3/1/18
to nod...@googlegroups.com
Hello,

I have a real time application which will require constant updates /
bug fixes. So I will be constantly defining new functions on
prototypes or constructors.

My question is, will there be a difference between functions which
were hard coded and functions defined using eval or Function
constructor? If so, will require() be possibly able to get around
this?

Note: Functions will be used multiple times throughout the lifetime of
the application. Giving this information just in case if they are
being optimized after the first usage.
Thank you

Zlatko

unread,
Mar 2, 2018, 9:06:06 AM3/2/18
to nodejs
Hi,

Good question! V8 Googlers say nothing eval does is optimized and almost absolutely must be avoided (and they same for Function constructor IIRC) - but what about the product of it?  I don't know, maybe you can run a few tests with v8-debug. I would be interested in results if you do run such a test.

But I have another question: why would you deploy new code this way? Can't you have some continuous deployment, partial rollouts etc this way? Or send all requests for unknown functionality to a pubsub, and then attach your new code there to respond?

Koray

unread,
Mar 2, 2018, 10:57:44 AM3/2/18
to nod...@googlegroups.com
Hello,

Thanks for your response. Main reason is I'm mostly a beginner so for
the time being this is the only way I know. There will be multiple
active sockets at any given time and they will be interacting, so I
want to be able to roll changes in without having to restart.

Koray
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/bbbd3192-1a76-4221-8be5-652794b3d693%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Parsa Ghadimi

unread,
Mar 2, 2018, 2:17:15 PM3/2/18
to nod...@googlegroups.com
Hi
You can take a look at Node's VM module. (require use that module internally).


> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/bbbd3192-1a76-4221-8be5-652794b3d693%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.

Zlatko

unread,
Mar 3, 2018, 9:49:04 PM3/3/18
to nodejs

Hi Koray,

Apparently, the answer to your original question is "yes", functions generated by "eval" or "new Function()" will get optimized. I've asked one of the V8 developers on Twitter, he even referred on how Webpack (pretty popular and well known JavaScript package) achieves crazy improvements on their latest iteration:



Koray

unread,
Mar 3, 2018, 11:54:44 PM3/3/18
to nod...@googlegroups.com
This is very useful to know. Thank you for your help.
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/d7e7e0a7-f604-425d-a689-2f6cc2e44ec5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages