node-websocket-client icon indicating copy to clipboard operation
node-websocket-client copied to clipboard

Optimize debug() calls for performance boost

Open pingdom-christian opened this issue 14 years ago • 1 comments

There are a few debug() calls in websocket.js that really slowed down our application. We have a high throughput of packets, and it turns out that sys.inspect() consumed almost 90% of the CPU time, which could be pinpointed down to these debug() calls.

Example:

debug('dataListener(' + sys.inspect(buf) + ')');

When we commented out these (for us) unnecessary calls, performance was substantially increased. I suppose you could create something like debugBuffer() and send buf as the argument. Inside the function you would then check the debug level before calling sys.inspect().

pingdom-christian avatar Sep 23 '11 12:09 pingdom-christian

+1

this single change just sped up my node server by a factor of 10!

davidfooks avatar Mar 30 '12 17:03 davidfooks