From d36d4f62f45e1360b1794fdd32ea9bf6fee0154b Mon Sep 17 00:00:00 2001 From: Rueian Date: Sun, 5 Jan 2025 13:09:44 -0800 Subject: [PATCH] perf: avoid unnecessary runtime.duffcopy when the compiler fails to inline the helper function Signed-off-by: Rueian --- client.go | 12 ++++++------ cluster.go | 16 ++++++++-------- helper.go | 6 +++--- mux.go | 12 ++++++------ pipe.go | 2 +- sentinel.go | 8 ++++---- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/client.go b/client.go index d3159a83..a0d9f713 100644 --- a/client.go +++ b/client.go @@ -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 @@ -100,7 +100,7 @@ retry: } } for i, cmd := range multi { - if resps[i].NonRedisError() == nil { + if resps[i].err == nil { cmds.PutCompleted(cmd) } } @@ -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) } } @@ -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 @@ -223,7 +223,7 @@ retry: goto retry } } - if resp.NonRedisError() == nil { + if resp.err == nil { cmds.PutCompleted(cmd) } return resp @@ -253,7 +253,7 @@ retry: goto retry } } - if resp[i].NonRedisError() == nil { + if resp[i].err == nil { cmds.PutCompleted(cmd) } } diff --git a/cluster.go b/cluster.go index 5fc1c3bf..e8eb6468 100644 --- a/cluster.go +++ b/cluster.go @@ -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 @@ -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 @@ -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) } } @@ -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 @@ -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 @@ -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) } } @@ -1308,7 +1308,7 @@ retry: } } } - if resp.NonRedisError() == nil { + if resp.err == nil { cmds.PutCompleted(cmd) } return resp @@ -1352,7 +1352,7 @@ retry: } } for i, cmd := range multi { - if resp[i].NonRedisError() == nil { + if resp[i].err == nil { cmds.PutCompleted(cmd) } } diff --git a/helper.go b/helper.go index 3d4c510d..6ab65f96 100644 --- a/helper.go +++ b/helper.go @@ -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 @@ -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 @@ -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]) } } diff --git a/mux.go b/mux.go index a9b06066..2ae185e2 100644 --- a/mux.go +++ b/mux.go @@ -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) @@ -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 } @@ -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 @@ -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 } @@ -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 @@ -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 } diff --git a/pipe.go b/pipe.go index 3be81043..318595eb 100644 --- a/pipe.go +++ b/pipe.go @@ -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 diff --git a/sentinel.go b/sentinel.go index 4518b187..c04e037d 100644 --- a/sentinel.go +++ b/sentinel.go @@ -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 @@ -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) } } @@ -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 @@ -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) } }