cap state map to 16 entries to prevent OOM in WASM

This commit is contained in:
realrasengan
2026-04-02 23:40:59 -07:00
parent d9db3986ba
commit 31b4ffccfc
+15
View File
@@ -107,6 +107,21 @@ func (st *stateTracker) applyDiff(diff []byte, oldNum, newNum, throwawayNum uint
}
}
// Hard cap: keep at most 16 states to prevent unbounded memory growth.
if len(st.states) > 16 {
minKeep := st.latestState
if minKeep > 16 {
minKeep -= 16
} else {
minKeep = 0
}
for n := range st.states {
if n < minKeep {
delete(st.states, n)
}
}
}
// Confirm predictions against server state.
latest := st.states[st.latestState]
if latest != nil {