body parser may speed up #367

Closed
kaven276 opened this Issue Sep 14, 2011 · 3 comments

Comments

Projects
None yet
2 participants
@kaven276

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);
}
next();
});

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

This comment has been minimized.

Show comment Hide comment
@tj

tj Sep 14, 2011

Member

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

Member

tj commented Sep 14, 2011

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

@kaven276

This comment has been minimized.

Show comment Hide comment
@kaven276

kaven276 Sep 15, 2011

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

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

This comment has been minimized.

Show comment Hide comment
@tj

tj Sep 15, 2011

Member

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

Member

tj commented Sep 15, 2011

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

@tj tj closed this Sep 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment