receive: Add map pooling and optimize sendLocalWrite to reduce alloca…#293
Open
receive: Add map pooling and optimize sendLocalWrite to reduce alloca…#293
Conversation
…tions This commit implements three optimizations targeting ~612GB of allocations (11% of total) identified through production CPU profiling. **Optimization 1: Distribution Map Pooling (357GB, 6.41%)** - Added sync.Pools for distribution maps (endpointReplicaMapPool, tenantSeriesMapPool) - Added helper functions for map clearing with size guards - Modified distributeTimeseriesToReplicas to use pools - Added cleanup in fanoutForward **Optimization 2: sendLocalWrite Improvements (255GB, 4.57%)** Part A: Pool tenantSeriesMapping (10.30GB) - Added tenantTimeseriesMappingPool sync.Pool - Modified sendLocalWrite to get/return map from pool Part B: Optimize loop and pre-allocate (244.65GB) - Changed loop iteration from value to index (avoids copying TimeSeries structs) - Pre-allocate slices with capacity hints (single-tenant and multi-tenant cases) - Lazy allocation for multi-tenant scenarios **Memory Safety:** - Size guards prevent pool ballooning (max 100 entries) - Maps cleared before reuse (no data leakage) - Error path cleanup prevents pool leaks **Testing:** - Added TestDistributionMapPooling - Added TestClearMapFunctions - All existing tests pass **Profiling Source:** Cluster: dev-aws-us-east-1-obs-integrationtest Namespace: pantheon Pod: pantheon-db-rep0-0 Date: 2026-02-06 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
…tions
This commit implements three optimizations targeting ~612GB of allocations (11% of total) identified through production CPU profiling.
Optimization 1: Distribution Map Pooling (357GB, 6.41%)
Optimization 2: sendLocalWrite Improvements (255GB, 4.57%)
Part A: Pool tenantSeriesMapping (10.30GB)
Part B: Optimize loop and pre-allocate (244.65GB)
Memory Safety:
Testing:
Profiling Source:
Cluster: dev-aws-us-east-1-obs-integrationtest
Namespace: pantheon
Pod: pantheon-db-rep0-0
Date: 2026-02-06
Changes
Verification