Skip to content

Commit

Permalink
perf: avoid unnecessary runtime.duffcopy when the compiler fails to i…
Browse files Browse the repository at this point in the history
…nline the helper function

Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Jan 5, 2025
1 parent d5937af commit d36d4f6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ retry:
goto retry
}
}
if resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
if resp.err == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
cmds.PutCompleted(cmd)
}
return resp
Expand Down Expand Up @@ -100,7 +100,7 @@ retry:
}
}
for i, cmd := range multi {
if resps[i].NonRedisError() == nil {
if resps[i].err == nil {
cmds.PutCompleted(cmd)
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ retry:
}
}
for i, cmd := range multi {
if err := resps[i].NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := resps[i].err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd.Cmd)
}
}
Expand All @@ -146,7 +146,7 @@ retry:
goto retry
}
}
if err := resp.NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := resp.err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd)
}
return resp
Expand Down Expand Up @@ -223,7 +223,7 @@ retry:
goto retry
}
}
if resp.NonRedisError() == nil {
if resp.err == nil {
cmds.PutCompleted(cmd)
}
return resp
Expand Down Expand Up @@ -253,7 +253,7 @@ retry:
goto retry
}
}
if resp[i].NonRedisError() == nil {
if resp[i].err == nil {
cmds.PutCompleted(cmd)
}
}
Expand Down
16 changes: 8 additions & 8 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (c *clusterClient) B() Builder {
}

func (c *clusterClient) Do(ctx context.Context, cmd Completed) (resp RedisResult) {
if resp = c.do(ctx, cmd); resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
if resp = c.do(ctx, cmd); resp.err == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
cmds.PutCompleted(cmd)
}
return resp
Expand Down Expand Up @@ -659,7 +659,7 @@ func (c *clusterClient) doresultfn(
ei := -1
clean = true
for i, resp := range resps {
clean = clean && resp.NonRedisError() == nil
clean = clean && resp.err == nil
ii := cIndexes[i]
cm := commands[i]
results.s[ii] = resp
Expand Down Expand Up @@ -803,7 +803,7 @@ retry:
}

for i, cmd := range multi {
if results.s[i].NonRedisError() == nil {
if results.s[i].err == nil {
cmds.PutCompleted(cmd)
}
}
Expand Down Expand Up @@ -851,7 +851,7 @@ process:

func (c *clusterClient) DoCache(ctx context.Context, cmd Cacheable, ttl time.Duration) (resp RedisResult) {
resp = c.doCache(ctx, cmd, ttl)
if err := resp.NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := resp.err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd)
}
return resp
Expand Down Expand Up @@ -984,7 +984,7 @@ func (c *clusterClient) resultcachefn(
) (clean bool) {
clean = true
for i, resp := range resps {
clean = clean && resp.NonRedisError() == nil
clean = clean && resp.err == nil
ii := cIndexes[i]
cm := commands[i]
results.s[ii] = resp
Expand Down Expand Up @@ -1097,7 +1097,7 @@ retry:
}

for i, cmd := range multi {
if err := results.s[i].NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := results.s[i].err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd.Cmd)
}
}
Expand Down Expand Up @@ -1308,7 +1308,7 @@ retry:
}
}
}
if resp.NonRedisError() == nil {
if resp.err == nil {
cmds.PutCompleted(cmd)
}
return resp
Expand Down Expand Up @@ -1352,7 +1352,7 @@ retry:
}
}
for i, cmd := range multi {
if resp[i].NonRedisError() == nil {
if resp[i].err == nil {
cmds.PutCompleted(cmd)
}
}
Expand Down
6 changes: 3 additions & 3 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func doMultiCache(cc Client, ctx context.Context, cmds []CacheableTTL, keys []st
resps := cc.DoMultiCache(ctx, cmds...)
defer resultsp.Put(&redisresults{s: resps})
for i, resp := range resps {
if err := resp.NonRedisError(); err != nil {
if err := resp.err; err != nil {
return nil, err
}
ret[keys[i]] = resp.val
Expand All @@ -247,7 +247,7 @@ func doMultiGet(cc Client, ctx context.Context, cmds []Completed, keys []string)
resps := cc.DoMulti(ctx, cmds...)
defer resultsp.Put(&redisresults{s: resps})
for i, resp := range resps {
if err := resp.NonRedisError(); err != nil {
if err := resp.err; err != nil {
return nil, err
}
ret[keys[i]] = resp.val
Expand All @@ -259,7 +259,7 @@ func doMultiSet(cc Client, ctx context.Context, cmds []Completed) (ret map[strin
ret = make(map[string]error, len(cmds))
resps := cc.DoMulti(ctx, cmds...)
for i, resp := range resps {
if ret[cmds[i].Commands()[1]] = resp.Error(); resp.NonRedisError() == nil {
if ret[cmds[i].Commands()[1]] = resp.Error(); resp.err == nil {
intl.PutCompletedForce(cmds[i])
}
}
Expand Down
12 changes: 6 additions & 6 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ block:
func (m *mux) blocking(pool *pool, ctx context.Context, cmd Completed) (resp RedisResult) {
wire := pool.Acquire()
resp = wire.Do(ctx, cmd)
if resp.NonRedisError() != nil { // abort the wire if blocking command return early (ex. context.DeadlineExceeded)
if resp.err != nil { // abort the wire if blocking command return early (ex. context.DeadlineExceeded)
wire.Close()
}
pool.Store(wire)
Expand All @@ -250,7 +250,7 @@ func (m *mux) blockingMulti(pool *pool, ctx context.Context, cmd []Completed) (r
wire := pool.Acquire()
resp = wire.DoMulti(ctx, cmd...)
for _, res := range resp.s {
if res.NonRedisError() != nil { // abort the wire if blocking command return early (ex. context.DeadlineExceeded)
if res.err != nil { // abort the wire if blocking command return early (ex. context.DeadlineExceeded)
wire.Close()
break
}
Expand All @@ -262,7 +262,7 @@ func (m *mux) blockingMulti(pool *pool, ctx context.Context, cmd []Completed) (r
func (m *mux) pipeline(ctx context.Context, cmd Completed) (resp RedisResult) {
slot := slotfn(len(m.wire), cmd.Slot(), cmd.NoReply())
wire := m.pipe(slot)
if resp = wire.Do(ctx, cmd); isBroken(resp.NonRedisError(), wire) {
if resp = wire.Do(ctx, cmd); isBroken(resp.err, wire) {
m.wire[slot].CompareAndSwap(wire, m.init)
}
return resp
Expand All @@ -273,7 +273,7 @@ func (m *mux) pipelineMulti(ctx context.Context, cmd []Completed) (resp *redisre
wire := m.pipe(slot)
resp = wire.DoMulti(ctx, cmd...)
for _, r := range resp.s {
if isBroken(r.NonRedisError(), wire) {
if isBroken(r.err, wire) {
m.wire[slot].CompareAndSwap(wire, m.init)
return resp
}
Expand All @@ -285,7 +285,7 @@ func (m *mux) DoCache(ctx context.Context, cmd Cacheable, ttl time.Duration) Red
slot := cmd.Slot() & uint16(len(m.wire)-1)
wire := m.pipe(slot)
resp := wire.DoCache(ctx, cmd, ttl)
if isBroken(resp.NonRedisError(), wire) {
if isBroken(resp.err, wire) {
m.wire[slot].CompareAndSwap(wire, m.init)
}
return resp
Expand Down Expand Up @@ -344,7 +344,7 @@ func (m *mux) doMultiCache(ctx context.Context, slot uint16, multi []CacheableTT
wire := m.pipe(slot)
resps = wire.DoMultiCache(ctx, multi...)
for _, r := range resps.s {
if isBroken(r.NonRedisError(), wire) {
if isBroken(r.err, wire) {
m.wire[slot].CompareAndSwap(wire, m.init)
return resps
}
Expand Down
2 changes: 1 addition & 1 deletion pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func (p *pipe) backgroundPing() {
}
ch := make(chan error, 1)
tm := time.NewTimer(p.timeout)
go func() { ch <- p.Do(context.Background(), cmds.PingCmd).NonRedisError() }()
go func() { ch <- p.Do(context.Background(), cmds.PingCmd).err }()
select {
case <-tm.C:
err = os.ErrDeadlineExceeded
Expand Down
8 changes: 4 additions & 4 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ retry:
goto retry
}
}
if resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
if resp.err == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
cmds.PutCompleted(cmd)
}
return resp
Expand Down Expand Up @@ -104,7 +104,7 @@ retry:
}
}
for i, cmd := range multi {
if resps.s[i].NonRedisError() == nil {
if resps.s[i].err == nil {
cmds.PutCompleted(cmd)
}
}
Expand All @@ -123,7 +123,7 @@ retry:
}

}
if err := resp.NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := resp.err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd)
}
return resp
Expand Down Expand Up @@ -151,7 +151,7 @@ retry:
}
}
for i, cmd := range multi {
if err := resps.s[i].NonRedisError(); err == nil || err == ErrDoCacheAborted {
if err := resps.s[i].err; err == nil || err == ErrDoCacheAborted {
cmds.PutCacheable(cmd.Cmd)
}
}
Expand Down

0 comments on commit d36d4f6

Please sign in to comment.