Skip to content

shard: skip hashmapStats allocation when stats are disabled#423

Open
c-tonneslan wants to merge 1 commit into
allegro:mainfrom
c-tonneslan:fix/skip-hashmapstats-alloc-when-stats-disabled
Open

shard: skip hashmapStats allocation when stats are disabled#423
c-tonneslan wants to merge 1 commit into
allegro:mainfrom
c-tonneslan:fix/skip-hashmapstats-alloc-when-stats-disabled

Conversation

@c-tonneslan

Copy link
Copy Markdown

`initNewShard` always built a `hashmapStats` map even when `StatsEnabled` was false. #420 dropped the capacity hint to 0 for that case, but `make` still returns a real empty map per shard, so the default `Config` still pays for an unused map header on every shard.

All `hashmapStats` writes (`hit`, `hitWithoutLock`, `del`) are already guarded by `s.statsEnabled`, and the reads in `getKeyMetadata{,WithLock}` return the zero value of `uint32` for a nil map, which is what they'd return for a missing key anyway. Leaving `hashmapStats` nil when stats are off is behaviour-preserving. `go test ./...` passes.

fixes #422

initNewShard always built a hashmapStats map even when StatsEnabled was
false. allegro#420 cut the capacity hint to 0 for that case, but make still
returned a real empty map per shard, so the default Config still paid
for an unused map header on every shard.

All hashmapStats writes (hit, hitWithoutLock, del) are already guarded
by s.statsEnabled, and the reads in getKeyMetadata{,WithLock} return
the zero value of uint32 for a nil map, which is what they'd return for
a missing key anyway. Leaving hashmapStats nil when stats are off is
behaviour-preserving.

Closes allegro#422

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hashmapStats allocated unconditionally regardless of StatsEnabled

1 participant