Skip to content

Commit

Permalink
perf: recycle the intermediate resp in the case of r2pipe.DoMulti
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Jun 27, 2023
1 parent 219ea26 commit 14a877e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ func (p *pipe) DoMulti(ctx context.Context, multi ...Completed) *redisresults {
}
return resp
} else if p.r2psFn != nil {
resultsp.Put(resp)
return p._r2pipe().DoMulti(ctx, multi...)
}
}
Expand Down Expand Up @@ -896,7 +897,7 @@ func (p *pipe) DoMulti(ctx context.Context, multi ...Completed) *redisresults {
p.background()
goto queue
}
resp.s = p.syncDoMulti(dl, ok, resp.s, multi)
p.syncDoMulti(dl, ok, resp.s, multi)
} else {
err := newErrResult(p.Error())
for i := 0; i < len(resp.s); i++ {
Expand Down Expand Up @@ -970,7 +971,7 @@ func (p *pipe) syncDo(dl time.Time, dlOk bool, cmd Completed) (resp RedisResult)
return newResult(msg, err)
}

func (p *pipe) syncDoMulti(dl time.Time, dlOk bool, resp []RedisResult, multi []Completed) []RedisResult {
func (p *pipe) syncDoMulti(dl time.Time, dlOk bool, resp []RedisResult, multi []Completed) {
if dlOk {
p.conn.SetDeadline(dl)
defer p.conn.SetDeadline(time.Time{})
Expand Down Expand Up @@ -999,7 +1000,7 @@ process:
}
resp[i] = newResult(msg, err)
}
return resp
return
abort:
if errors.Is(err, os.ErrDeadlineExceeded) {
err = context.DeadlineExceeded
Expand All @@ -1010,7 +1011,7 @@ abort:
for i := 0; i < len(resp); i++ {
resp[i] = newErrResult(err)
}
return resp
return
}

func syncRead(r *bufio.Reader) (m RedisMessage, err error) {
Expand Down

0 comments on commit 14a877e

Please sign in to comment.