Skip to content

receive: Add map pooling and optimize sendLocalWrite to reduce alloca…#293

Open
mkusumdb wants to merge 1 commit intodb_mainfrom
kusum-madarasu_data/ad1
Open

receive: Add map pooling and optimize sendLocalWrite to reduce alloca…#293
mkusumdb wants to merge 1 commit intodb_mainfrom
kusum-madarasu_data/ad1

Conversation

@mkusumdb
Copy link
Collaborator

@mkusumdb mkusumdb commented Feb 6, 2026

…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

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

…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>
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.

1 participant