Skip to content

Commit 5bf8efe

Browse files
authored
chore: Improve insertReportIntoSizes to reduce memory allocations (#7456)
<!-- Describe what has changed in this PR --> **What changed?** Improve insertReportIntoSizes to reduce memory allocations <!-- Tell your future self why have you made these changes --> **Why?** To reduce memory allocation <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** unit tests (this method is covered by unit test) <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes**
1 parent d4243c7 commit 5bf8efe

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

service/worker/scanner/shardscanner/aggregators.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,9 @@ func (a *ShardScanResultAggregator) insertReportIntoSizes(report ScanReport) {
497497
}
498498
insertIndex++
499499
}
500-
newShardSizes := append([]ShardSizeTuple{}, a.shardSizes[0:insertIndex]...)
501-
newShardSizes = append(newShardSizes, tuple)
502-
newShardSizes = append(newShardSizes, a.shardSizes[insertIndex:]...)
503-
a.shardSizes = newShardSizes
500+
a.shardSizes = append(a.shardSizes, ShardSizeTuple{})
501+
copy(a.shardSizes[insertIndex+1:], a.shardSizes[insertIndex:])
502+
a.shardSizes[insertIndex] = tuple
504503
}
505504

506505
// GetShardDistributionStats returns aggregated size statistics

0 commit comments

Comments
 (0)