Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeated code in the lib/commander, not recommended arguments use #35

Closed
AVVS opened this issue May 15, 2015 · 1 comment
Closed

repeated code in the lib/commander, not recommended arguments use #35

AVVS opened this issue May 15, 2015 · 1 comment

Comments

@AVVS
Copy link
Collaborator

AVVS commented May 15, 2015

There are code parts like this https://github.com/luin/ioredis/blob/master/lib/commander.js#L43-L53

      var args = _.toArray(arguments);
      var callback;

      if (typeof args[args.length - 1] === 'function') {
        callback = args.pop();
      }

      var options = { replyEncoding: 'utf8' };
      if (this.options.showFriendlyErrorStack) {
        options.errorStack = new Error().stack;
      }

Part about the arguments: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments

I understand that there is lots of boilerplate code, but it is supposed to speed up the module quite a bit

smth: function() {
   var length = arguments.length;
   var lastArgIndex = length - 1;
   var callback = arguments[lastArgIndex];
   if (typeof callback !== 'function') {
      callback = undefined;
   } else {
      length = lastArgIndex;
   }
   var args = new Array(length);
   for (var i = 0; i < length; i++) {
      args[i] = arguments[i];
   }

   // .... options part

   var command = new Command(commandName, args, options, callback);
   return this.sendCommand(command);
}
@luin luin closed this as completed in 20df742 May 16, 2015
@luin
Copy link
Collaborator

luin commented May 16, 2015

Released in 1.3.1. These changes improves the performance a lot. Thank you for pointing this out :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants