From b6680398c31239220543179d02a6e7074004030b Mon Sep 17 00:00:00 2001 From: claude Date: Thu, 6 Aug 2026 02:08:05 +0400 Subject: [PATCH] tick: dedupe rule-by-name map building (V-581) stopFinishedAlarms and repeatableRules each built their own map[string]rule (one keyed to loop.Rule, one to bool) from t.rules on every call. Factored into rulesByName(), one map[string]loop.Rule both callers read. --- cmd/mavend/tick.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/mavend/tick.go b/cmd/mavend/tick.go index 9de2b74..76b0911 100644 --- a/cmd/mavend/tick.go +++ b/cmd/mavend/tick.go @@ -319,10 +319,7 @@ func (t *tickLoop) stopFinishedAlarms(ctx context.Context, keys []string, state if len(keys) == 0 { return nil } - byName := make(map[string]loop.Rule, len(t.rules)) - for _, r := range t.rules { - byName[r.Name] = r - } + byName := t.rulesByName() live := keys[:0:0] for _, key := range keys { outcome := "" @@ -381,19 +378,27 @@ func (t *tickLoop) repeatableRules(keys []string) []string { if len(keys) == 0 { return nil } - wired := make(map[string]bool, len(t.rules)) - for _, r := range t.rules { - wired[r.Name] = true - } + wired := t.rulesByName() out := keys[:0:0] for _, k := range keys { - if wired[k] { + if _, ok := wired[k]; ok { out = append(out, k) } } return out } +// rulesByName indexes the wired rule set by name, for the two lookups above +// that only care whether a key is still wired (repeatableRules) or need the +// rule itself (stopFinishedAlarms). +func (t *tickLoop) rulesByName() map[string]loop.Rule { + byName := make(map[string]loop.Rule, len(t.rules)) + for _, r := range t.rules { + byName[r.Name] = r + } + return byName +} + // cachePhrase keeps the latest phrased nudge per rule for the sev4-repeat // path. writing under a mutex; the repeat path reads under the same. the // cache is bounded by the rule count (≤ ~30 per spec) so eviction is not a