On Sun, Apr 8, 2012 at 00:38, Jann Horn <[email protected]> wrote: > Hello, > I've been using a little ad-filtering proxy I built using node for some > time now, and today I had a look at its CPU usage while flash was > prefetching a very large youtube video. Well, it was relatively high, I > think, but the only thing it should be doing at that time is using > the .pipe() method to pipe from one HTTP stream to another one. > > Well, I was surprised to see that node was wasting ~2.5% of its CPU > usage on v8::String::New calls in node::MakeCallback, and that > node::MakeCallback in total has a CPU overhead that amounts to ~7% of > the total CPU time node uses in this case. Shouldn't it at least be > possible to cache the symbol string? And couldn't node maybe also avoid > calling v8::Object::Get each time it wants to call into userland (~3.6% > )? > > Are these things right or did I make some huge mistake? If they are > right, would it be possible to make this stuff a bit faster? Reducing > the CPU usage by 5% seems like a relatively big speed improvement to me. > > Node version: 0.6.14 > > Call graph centered on MakeCallback: > http://thejh.github.com/callgraph.png > > Raw callgrind output: > http://thejh.github.com/callgrind.out.19701
Yes, it's a known issue and something we'll address in v0.8, probably by scrapping MakeCallback() and moving back to Persistent<T> handles. In case you're interested, [1] is a branch where I did some performance benchmarking. It turns out that MakeCallback() and V8's thread-local storage functions (used to store the Isolate handle) are the two most expensive functions. The overhead is not terribly bad, just... mildly bad. In my tests roughly 5% of total user CPU time is spent in those two functions. [1] https://github.com/bnoordhuis/node/compare/benchmark
