Clone and build Node for analysis:
$ git clone https://github.com/joyent/node.git
$ cd node
$ export GYP_DEFINES="v8_enable_disassembler=1"
$ ./configure
$ make -j4
// Thanks to @isntitvacant (https://github.com/chrisdickinson) for optimizing the | |
// bit shift performance tweaks. | |
var SB = require('buffer').SlowBuffer; | |
var ITER = 2e4; | |
var SIZE = 1e3; | |
function genPrimes(max) { | |
var primes = new Array(); | |
var len = (max >>> 3) + 1; |
Disclaimer: I work for Mozilla and am a Node.js core maintainer. The opinions expressed here do not reflect those of Mozilla or the Node.js project.
After watching the events unfold the last 2 days I decided to sit down, with my two cartons of Trader Joe's eggnog, and simply express with all humility and confidence what libuv@47d98b6 definitely was not.
Over the last year I have had the pleasure of being mentored by Ben. He is largely responsible for my initial major involvement writing performance improvements for Node, and has easily surpassed
The prep-script.sh
will setup the latest Node and install the latest perf version on your Linux box.
When you want to generate the flame graph, run the following (folder locations taken from install script):
sudo sysctl kernel.kptr_restrict=0
# May also have to do the following:
# (additional reading http://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar )
sudo sysctl kernel.perf_event_paranoid=0
var TCP = process.binding('tcp_wrap').TCP; | |
var SlowBuffer = require('buffer').SlowBuffer; | |
var util = require('util'); | |
var err; | |
var headers = 'HTTP/1.1 200 OK\r\n' + | |
'Connection: Keep-Alive\r\n' + | |
'Content-Type: text/plain; charset=latin-1\r\n' + | |
'Content-Length: 12\r\n\r\n' + | |
'hello world\n'; |
#include <stdio.h> | |
#include <assert.h> | |
#include "uv.h" | |
#define ITER 1e6 | |
#define ACCESS_ONCE(type, var) \ | |
(*(volatile type*) &(var)) | |
static uv_mutex_t mutex; |
Notes:
On process.nextTick()
:
/**
* Ordered fastest to slowest.
* Different ways to extract data from a Buffer in C++.
*/
void RunMe(const FunctionCallbackInfo<Value>& args) {
/*
Local<Object> buf = args[0].As<Object>();
char* data = static_cast(buf->GetIndexedPropertiesExternalArrayData());
//enter with m<nn/2 and n<nn/2 | |
function hyp(x, n, m, nn) { | |
var nz, mz; | |
// best to have n<m | |
if (m < n) { | |
nz = m; | |
mz = n | |
} else { | |
nz = n; |
Here is a collection of tips and tricks I've picked up about doing performance analysis on Node. Included is a build script that should get a base install of Ubuntu fully functional and ready for all the things we'll be going through.
The script pulls a lot of code from the latest master
of each repository. So
it's possible that something may fail, but to date I haven't had any issues.
First, go ahead and run the script. Then go take a nice long break. It'll