From d34224444e049161c83557e72e88943bd732d89d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 2 Oct 2020 17:34:14 +1000 Subject: Use builtin eq var in rate and stmutil In particular, in the rate limiter this gives a massive performance increase. --- rate/ratelimit.go | 2 +- stmutil/context.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rate/ratelimit.go b/rate/ratelimit.go index 69d6932..a44f383 100644 --- a/rate/ratelimit.go +++ b/rate/ratelimit.go @@ -37,7 +37,7 @@ func Every(interval time.Duration) Limit { func NewLimiter(rate Limit, burst numTokens) *Limiter { rl := &Limiter{ max: stm.NewVar(burst), - cur: stm.NewVar(burst), + cur: stm.NewBuiltinEqVar(burst), lastAdd: stm.NewVar(time.Now()), rate: rate, } diff --git a/stmutil/context.go b/stmutil/context.go index 315abf4..8a4d58d 100644 --- a/stmutil/context.go +++ b/stmutil/context.go @@ -23,7 +23,7 @@ func ContextDoneVar(ctx context.Context) (*stm.Var, func()) { if ctx.Err() != nil { // TODO: What if we had read-only Vars? Then we could have a global one for this that we // just reuse. - v := stm.NewVar(true) + v := stm.NewBuiltinEqVar(true) return v, func() {} } v := stm.NewVar(false) -- cgit v1.2.3