Skip to content
This repository

body parser may speed up #367

kaven276 opened this Issue September 14, 2011 · 3 comments

2 participants

kaven276 TJ Holowaychuk

Below is some code in bodyParser.js

req.on('data', function(chunk) { data += chunk; });
req.on('end', function(){
req.rawBody = data;
try {
req.body = data
? parser(data)
: {};
} catch (err) {
return next(err);

I think " data += chunk; " should change to data.push(chunk)
and in "req.on('end', function(){ " add data = data.join('');
string append will do repeating work and may lose effeciency, so use array and join once at end .

TJ Holowaychuk

if you could provide (real) benchmarks on an average sized body we can change it, otherwise this is just a micro-optimization


yes, you are right now, browser will not send much url-encoded/json body
but in future or other client and other area, there may have client who send large set of req body in json/xml
In practise now, there may no need to optimize code, but optimiztion should applied in everyday coding if it's trival to do

TJ Holowaychuk

meh if they're pretty similar it doesn't really matter

TJ Holowaychuk visionmedia closed this September 14, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.