Node.js performance tips
Fine tuning your deployment for maximum performance is always a top priority. Node.js’ chief mechanic shows you how to put the pedal to the metal.
My $.02. Trevor is smart. Really, really smart. This talk was amazing and will be basis for some follow-up posts (once I have a chance to grok everything he discussed.)
Run node with
How to inspect JS in gdb
dgd -d lib/ -d src/
Trever along with every Node contributor in the room repeatedly said to not use sync calls. This should be a wake up call if you’re still depending on anything sync.
It’s common practice to nest functions, but don’t do this. Create functions all the way down and unnest callbacks using named functions.
Trevor wrote (psycho-proxy)[github.com/trevnorris/psycho-proxy] to see how close he could get to nginx’s proxy performance. It’s an example of hyper-tuned code, but is not something you should use.
Naming and hoisting functions is more efficient than using anonymous callbacks.
Q: Are there any plans to support an engine other than v8?
A: They would like it, but the node api and v8 are tightly coupled, plus v8 is rapidly changing.
Someone from the audience stated that this is not a priority currently.
The amount of GC time I experience is driven by the number of objects and number of references to those objects.
Try to keep things in direct scope.
Create type stable function = call each function with the same params in the same positions with the same types each time. This allows v8 to optimize the function.
Important Point: Coding for Node is different from coding for the web. If you are just creating a normal web app then some of what Trevor suggests is not necessary.
However, if you’re coding for Node then knowing C++ helps a lot. Tools to use include strace, gdb, etc. He listed a bunch of tools but I did not have a chance to write everything down.
We specialize in helping professional developers, like you, expand your skill set. Our courses are focused on enabling you to learn everything necessary to use a new technology in a live, production application.
All courses are made with love in
Palo Alto, CA.
Subscribe to our newsletter