Skip to content

Commit fce8679

Browse files
committed
perf(pool): use predefined state transition slices
Eliminate dynamic slice allocations on hot paths by using predefined global slices for common state transitions.
1 parent b352557 commit fce8679

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/redis/go-redis/v9
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/bsm/ginkgo/v2 v2.12.0

internal/pool/conn_state.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ const (
4141
StateClosed
4242
)
4343

44+
// Predefined state transition slices to avoid allocations on hot paths.
45+
// These are used by TryTransition and AwaitAndTransition to specify valid source states.
46+
var (
47+
// Common single-state transitions
48+
validFromIdle = []ConnState{StateIdle}
49+
validFromInUse = []ConnState{StateInUse}
50+
51+
// Common multi-state transitions
52+
validFromCreatedOrIdle = []ConnState{StateCreated, StateIdle}
53+
validFromInitializingOrUnusable = []ConnState{StateInitializing, StateUnusable}
54+
validFromCreatedIdleOrUnusable = []ConnState{StateCreated, StateIdle, StateUnusable}
55+
validFromInUseIdleOrCreated = []ConnState{StateInUse, StateIdle, StateCreated}
56+
)
57+
4458
// String returns a human-readable string representation of the state.
4559
func (s ConnState) String() string {
4660
switch s {

0 commit comments

Comments
 (0)