perf: serve long-range studies from a decoded closed-day cache
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4143bf599e
commit
4ca9c7bf0c
16 files changed
+846
-83
No files matched your search
@@ -8,6 +8,8 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -58,6 +60,28 @@ var (
|
||||
// NormPath normalises a path for signatures: query dropped, lowercase, uuids
|
||||
// and long hex runs become {id}, digit runs become {n}.
|
||||
func NormPath(p string) string {
|
||||
if v, ok := normMemo.Load(p); ok {
|
||||
return v.(string)
|
||||
}
|
||||
n := normPath(p)
|
||||
if normMemoN.Add(1) > normMemoMax { // bounded: paths come from attackers
|
||||
normMemo.Clear()
|
||||
normMemoN.Store(1)
|
||||
}
|
||||
normMemo.Store(p, n)
|
||||
return n
|
||||
}
|
||||
|
||||
// Paths repeat heavily in a study and the three regular expressions are the
|
||||
// costliest step of a signature, so results are memoised.
|
||||
const normMemoMax = 50000
|
||||
|
||||
var (
|
||||
normMemo sync.Map
|
||||
normMemoN atomic.Int64
|
||||
)
|
||||
|
||||
func normPath(p string) string {
|
||||
if i := strings.IndexAny(p, "?#"); i >= 0 {
|
||||
p = p[:i]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user