Commit Graph
1 Commits
Author SHA1 Message Date
yetone 002b4eb080 sessions: prefixHash reads into one pooled buffer instead of io.CopyN's
io.CopyN made a new buffer for every call, and for each of the 16
samples of a long file (64 KB a call). Every session and call log is
hashed this way on a cold start: io.copyBuffer via prefixHash was 0.78 GB
of 11.57 GB allocated in the first 2 minutes. It now reads into a pooled
64 KB array: ReadFull for a short prefix, ReadAt for each sample. A
sample short of its window is still unknown (""), as CopyN's error was.
The hash is byte-for-byte the same, so stored sample-v1 hashes still
match.

Run:
- TestPrefixHashUnchangedAndUnbuffered (new): equal to the old
  CopyN code at 0, 1, 4095, 4096, 65535, 65536, 65537, 1 MiB and 3 MiB,
  and "" past the end as before; with prefixHash pointed back at the old
  code it is red, "hashing a long log allocated 65 KB"; green now (under
  -race the pool drops some puts, 13 KB, so the bar is 24 KB).
- go test ./internal/sessions/ with -race ok; -race -count=5 on the new
  test ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ok.
2026-10-21 18:19:47 +08:00