perf(query,types): lazy-init ShardedMap + inline small-input math#9718
Open
shaunpatterson wants to merge 2 commits into
Open
perf(query,types): lazy-init ShardedMap + inline small-input math#9718shaunpatterson wants to merge 2 commits into
shaunpatterson wants to merge 2 commits into
Conversation
shards becomes a [30]map fixed array (one heap alloc for the struct); shard maps are created lazily on first write. Adds PeekShard (read-only, no alloc) and makes GetShardOrNil lazily allocate. Also fixes IsEmpty, which previously returned false for any non-nil map (it checked len(shards)) and now reports true when all shards are empty. BenchmarkShardedMap: New: 560.8n -> 0.25n, 30 allocs -> 0 SetGet: 1060n -> 682n, 38 allocs -> 16 (-57.9%)
types: ShardedMap.shards becomes a [30]map fixed array (one heap alloc for the struct) with shard maps created lazily on first write. Adds PeekShard (read-only, no alloc), makes GetShardOrNil lazily allocate, and fixes IsEmpty (previously returned false for any non-nil map; now reports true when empty). query: processBinary processes small inputs (<512 total entries) inline instead of launching 30 goroutines + a WaitGroup, using PeekShard for read-only shard access. These are bundled because the inline math path depends on PeekShard. BenchmarkShardedMap: New 560n->0.25n (30->0 allocs); SetGet 38->16 allocs. BenchmarkProcessBinarySmall: n=8 8.9µs->2.2µs (-75%, 233->60 allocs).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
types:
ShardedMap.shardsbecomes a[30]mapfixed array (one alloc for the struct) with shard maps created lazily on first write. AddsPeekShard(read-only, no alloc), makesGetShardOrNillazily allocate, and fixesIsEmpty(previously returned false for any non-nil map; now true when empty).query:
processBinaryhandles small inputs (<512 entries) inline instead of launching 30 goroutines + a WaitGroup, usingPeekShardfor read-only access.Bundled because the inline math path depends on
PeekShard.BenchmarkShardedMap: New 560n→0.25n (30→0 allocs).BenchmarkProcessBinarySmall: n=8 8.9µs→2.2µs (-75%).Independent change; branched from
4b9b399d(no dependency on the other PRs in this set). Verified: package unit tests pass + Go benchmark (benchstat, p<0.01). Numbers are single-thread microbenchmarks; not yet run through the Docker integration suite.