Skip to content

Commit 785af29

Browse files
committed
Merge pull request #842 from fintura/speedup
Small speedup: do not call data.toString() on debug messages
2 parents 4a8da6d + e6aa382 commit 785af29

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ try {
2828
parsers.push(require("./lib/parser/hiredis"));
2929
} catch (err) {
3030
/* istanbul ignore next: won't be reached with tests */
31-
debug("hiredis parser not installed.");
31+
debug("Hiredis parser not installed.");
3232
}
3333

3434
parsers.push(require("./lib/parser/javascript"));
@@ -130,7 +130,7 @@ RedisClient.prototype.initialize_retry_vars = function () {
130130

131131
RedisClient.prototype.unref = function () {
132132
if (this.connected) {
133-
debug("unref'ing the socket connection");
133+
debug("Unref'ing the socket connection");
134134
this.stream.unref();
135135
} else {
136136
debug("Not connected yet, will unref later");
@@ -327,7 +327,7 @@ RedisClient.prototype.on_ready = function () {
327327
};
328328
Object.keys(this.subscription_set).forEach(function (key) {
329329
var parts = key.split(" ");
330-
debug("sending pub/sub on_ready " + parts[0] + ", " + parts[1]);
330+
debug("Sending pub/sub on_ready " + parts[0] + ", " + parts[1]);
331331
callback_count++;
332332
self.send_command(parts[0] + "scribe", [parts[1]], callback);
333333
});
@@ -386,7 +386,7 @@ RedisClient.prototype.on_info_cmd = function (err, res) {
386386
RedisClient.prototype.ready_check = function () {
387387
var self = this;
388388

389-
debug("checking server ready state...");
389+
debug("Checking server ready state...");
390390

391391
this.send_anyway = true; // secret flag to send_command to send something even if not "ready"
392392
this.info(function (err, res) {
@@ -447,7 +447,7 @@ RedisClient.prototype.connection_gone = function (why) {
447447
// If this is a requested shutdown, then don't retry
448448
if (this.closing) {
449449
this.retry_timer = null;
450-
debug("connection ended from quit command, not retrying.");
450+
debug("Connection ended from quit command, not retrying.");
451451
return;
452452
}
453453

@@ -464,7 +464,7 @@ RedisClient.prototype.connection_gone = function (why) {
464464
this.retry_timer = null;
465465
// TODO - some people need a "Redis is Broken mode" for future commands that errors immediately, and others
466466
// want the program to exit. Right now, we just log, which doesn't really help in either case.
467-
debug("node_redis: Couldn't get Redis connection after " + this.max_attempts + " attempts.");
467+
debug("Couldn't get Redis connection after " + this.max_attempts + " attempts.");
468468
return;
469469
}
470470

@@ -481,7 +481,7 @@ RedisClient.prototype.connection_gone = function (why) {
481481
if (self.connect_timeout && self.retry_totaltime >= self.connect_timeout) {
482482
self.retry_timer = null;
483483
// TODO - engage Redis is Broken mode for future commands, or whatever
484-
debug("node_redis: Couldn't get Redis connection after " + self.retry_totaltime + "ms.");
484+
debug("Couldn't get Redis connection after " + self.retry_totaltime + "ms.");
485485
return;
486486
}
487487

@@ -492,7 +492,8 @@ RedisClient.prototype.connection_gone = function (why) {
492492
};
493493

494494
RedisClient.prototype.on_data = function (data) {
495-
debug("net read " + this.address + " id " + this.connection_id + ": " + data.toString());
495+
// The data.toString() has a significant impact on big chunks and therefor this should only be used if necessary
496+
// debug("Net read " + this.address + " id " + this.connection_id + ": " + data.toString());
496497

497498
try {
498499
this.reply_parser.execute(data);
@@ -570,7 +571,7 @@ RedisClient.prototype.return_reply = function (reply) {
570571
}
571572

572573
if (this.pub_sub_mode && (type === 'message' || type === 'pmessage')) {
573-
debug("received pubsub message");
574+
debug("Received pubsub message");
574575
}
575576
else {
576577
command_obj = this.command_queue.shift();
@@ -602,7 +603,7 @@ RedisClient.prototype.return_reply = function (reply) {
602603

603604
command_obj.callback(null, reply);
604605
} else {
605-
debug("no callback for reply: " + (reply && reply.toString && reply.toString()));
606+
debug("No callback for reply");
606607
}
607608
} else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) {
608609
if (Array.isArray(reply)) {
@@ -725,12 +726,11 @@ RedisClient.prototype.send_command = function (command, args, callback) {
725726

726727
command_obj = new Command(command, args, false, buffer_args, callback);
727728

728-
if ((!this.ready && !this.send_anyway) || !stream.writable) {
729-
if (!stream.writable) {
730-
debug("send command: stream is not writeable.");
731-
}
732-
729+
if (!this.ready && !this.send_anyway || !stream.writable) {
733730
if (this.enable_offline_queue) {
731+
if (!stream.writable) {
732+
debug("send command: stream is not writeable.");
733+
}
734734
debug("Queueing " + command + " for next server connection.");
735735
this.offline_queue.push(command_obj);
736736
this.should_buffer = true;
@@ -767,18 +767,18 @@ RedisClient.prototype.send_command = function (command, args, callback) {
767767

768768
command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n";
769769

770-
if (! buffer_args) { // Build up a string and send entire command in one write
770+
if (!buffer_args) { // Build up a string and send entire command in one write
771771
for (i = 0, il = args.length, arg; i < il; i += 1) {
772772
arg = args[i];
773773
if (typeof arg !== "string") {
774774
arg = String(arg);
775775
}
776776
command_str += "$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n";
777777
}
778-
debug("send " + this.address + " id " + this.connection_id + ": " + command_str);
778+
debug("Send " + this.address + " id " + this.connection_id + ": " + command_str);
779779
buffered_writes += !stream.write(command_str);
780780
} else {
781-
debug("send command (" + command_str + ") has Buffer arguments");
781+
debug("Send command (" + command_str + ") has Buffer arguments");
782782
buffered_writes += !stream.write(command_str);
783783

784784
for (i = 0, il = args.length, arg; i < il; i += 1) {

0 commit comments

Comments
 (0)