4

Are performance effects when using JavaScript anonymous functions also applicable for node.js programs when most of the code in the wild is network/http oriented and processing requests, connections and such is mostly done through anonymous functions? Can this lead to potential performance drop during higher traffic load?

Community
  • 1
  • 1
yojimbo87
  • 65,684
  • 25
  • 123
  • 131

1 Answers1

6

It really depends on your code, and without measuring it, you cannot know. But in general, you can be quite sure that the time spent waiting for I/O significantly outweighs the time spent creating callback functions for handling these I/O events. Therefore, in normal scenarios there is probably no significant (or even no measurable) gain in optimizing the creation of callbacks. There are likely other areas where it is easier to gain performance and to find them you have to profile your code.

alienhard
  • 14,376
  • 9
  • 37
  • 28
  • A useful answer. However, aiming towards separately declared (anonymous or non) functions can be a readability aid, whether or not the performance impacts are significant: overusing callbacks that are anonymously declared inline with whatever invokes them can lead to less-legible, heavily nested code. – Zac B Aug 01 '12 at 14:36