Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http.js: util.inspect() called even when debug is off. #1546

Closed
bgaff opened this issue Aug 17, 2011 · 4 comments
Closed

http.js: util.inspect() called even when debug is off. #1546

bgaff opened this issue Aug 17, 2011 · 4 comments
Labels

Comments

@bgaff
Copy link

bgaff commented Aug 17, 2011

When process.env.NODE_DEBUG is not defined, then in lib/http.js the debug function is defined as function () { } (line 35). Nonetheless, in OutgoingMessage.prototype.write it calls debug as: debug('string chunk = ' + util.inspect(chunk)) (line 612), thus even when debug is disabled util.inspect() is being called, after profiling I found that my application was spending a considerable amount of time in util.inspect(). Fixing this bug resulted in a considerable performance improvement.

@isaacs
Copy link

isaacs commented Aug 17, 2011

Are you running node_g? I thought that the debug() calls were stripped out by a macro in the non-debug binary builds?

@koichik
Copy link

koichik commented Aug 17, 2011

@isaacs - since v0.4.8, debug statements has been enabled in normal build (c409aab).

@isaacs
Copy link

isaacs commented Aug 17, 2011

Oh, I see. Then this is a valid issue.

@ry
Copy link

ry commented Aug 17, 2011

Benching version 5e37e10. Applied this change to http_simple.js to avoid hot path

diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js
index 8d66190..8dbbf06 100644
--- a/benchmark/http_simple.js
+++ b/benchmark/http_simple.js
@@ -85,8 +85,8 @@ var server = http.createServer(function (req, res) {

   res.writeHead(status, { "Content-Type": "text/plain",
                           "Content-Length": content_length });
-  res.end(body);
-
+  res.write(body);
+  res.end();
 });

 server.listen(port, function () {

ab -t 10 -c 1 http://127.0.0.1:8000/bytes/12345 | grep Req

With fix:
1814.68
1817.17
1814.15

Without fix:
1808.33
1811.59
1824.45

@ry ry closed this as completed in 9cd5108 Aug 17, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants