In performance-sensitive paths, actively control hidden costs: cap buffering, reuse expensive compiled primitives, and avoid full serialization/large allocations.
Apply these rules: 1) Bound buffering/reads in streaming probes
Example pattern (mimicking the approach):
if !preReadUntilContent && len(buffered) >= maxPreReadEvents {
break // stop buffering; avoid response delay/unbounded growth
}
2) Hoist heavy compiled expressions
regexp.MustCompile(...) to package/module scope and reuse.3) Replace full serialization with cheap deterministic signatures
json.Marshal of large structs/slices when you only need routing/decision equivalence.Example pattern (self-contained):
func associationSignature(a []*MyAssociation) uint64 {
h := fnv.New64a()
for _, x := range a {
// Write only semantically relevant fields
h.Write([]byte(x.TargetType))
h.Write([]byte{byte(x.Enabled)})
for _, c := range x.Conditions {
h.Write([]byte(c.Key))
h.Write([]byte(c.Operator))
h.Write([]byte(c.Value))
}
}
return h.Sum64()
}
4) Test what changed semantics