A state was 424 bytes, so each one decodeCache and parseRead make took a
448-byte slot. HeadSize is the length of a head of headLen (256) bytes
at most; as an int32 beside CdRead it saves 8 bytes, and a state is 416,
32 bytes less held per session file (~0.58MB for 18k files).
Run (mote, real-account copy, idle 180s, network blocked):
- decodeCache's inuse 26.01MB -> 23MB, reflect.unsafe_New 15.51MB ->
12MB. The profile samples every 512KB, so more than the ~0.58MB the
size class accounts for is sampling, not this change.
- TestStateFitsItsSizeClass: green; red on the old int by hand ("a state
is 424 bytes, over the 416-byte size class").
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
gofmt clean. The cache's JSON keeps head_size as a number, so an old
cache reads as before.
Not tried: the full suite (state is unexported, only internal/sessions
reads it).
16 lines
439 B
Go
16 lines
439 B
Go
package sessions
|
|
|
|
import (
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
// Every file of a history keeps its state, made one by one (decodeCache's
|
|
// reflect.New, parseRead's &state{}), so a state is held in the smallest
|
|
// size class it fits: 416 bytes, not the 448 a 424-byte state took (#2278).
|
|
func TestStateFitsItsSizeClass(t *testing.T) {
|
|
if n := unsafe.Sizeof(state{}); n > 416 {
|
|
t.Fatalf("a state is %d bytes, over the 416-byte size class", n)
|
|
}
|
|
}
|