Browse files

Performance enhancement in non-reconnect mode

If we aren't in reconnect mode, using __with_reconnect adds a method call
and a closure invocation to every request, no matter how trivial.  This
change adds a fast path for directly calling __run_cmd in the three relevant
locations.  In my tests, this saves up to a third of the best-case amortised
per-request execution time.
  • Loading branch information...
1 parent 9c18872 commit 05a29738dd234745bee7373b0a3e5b3ee8d6d5a5 @arc committed Mar 8, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/Redis.pm
View
12 lib/Redis.pm
@@ -231,6 +231,10 @@ sub __std_cmd {
# from that command, rather than throwing an exception immediately.
my $collect_errors = $cb && uc($command) eq 'EXEC';
+ ## Fast path, no reconnect;
+ return $self->__run_cmd($command, $collect_errors, undef, $cb, @_)
+ unless $self->{reconnect};
+
my @cmd_args = @_;
$self->__with_reconnect(sub {
$self->__run_cmd($command, $collect_errors, undef, $cb, @cmd_args);
@@ -348,6 +352,10 @@ sub info {
my $cb = @_ && ref $_[-1] eq 'CODE' ? pop : undef;
+ ## Fast path, no reconnect
+ return $self->__run_cmd('INFO', 0, $custom_decode, $cb, @_)
+ unless $self->{reconnect};
+
my @cmd_args = @_;
$self->__with_reconnect(sub {
$self->__run_cmd('INFO', 0, $custom_decode, $cb, @cmd_args);
@@ -369,6 +377,10 @@ sub keys {
my $cb = @_ && ref $_[-1] eq 'CODE' ? pop : undef;
+ ## Fast path, no reconnect
+ return $self->__run_cmd('KEYS', 0, $custom_decode, $cb, @_)
+ unless $self->{reconnect};
+
my @cmd_args = @_;
$self->__with_reconnect(sub {
$self->__run_cmd('KEYS', 0, $custom_decode, $cb, @cmd_args);

0 comments on commit 05a2973

Please sign in to comment.