Skip to content

Conversation

@mariomac
Copy link

The GenericMap's Copy method is run in diverse stages of the pipeline, for each processed flow.

Preallocating the map size to the expected resulting size can improve Copy CPU performance and memory allocations by 40%-50%.

Benchmark results with 20-entries maps (before vs after):

BenchmarkGenericMap_Copy-12       658083              1671 ns/op            1852 B/op          2 allocs/op
BenchmarkGenericMap_Copy-12       978686              1082 ns/op            1199 B/op          1 allocs/op

Benchmark results with 30-entries maps (before vs after):

BenchmarkGenericMap_Copy-12       354102              3280 ns/op            4337 B/op          4 allocs/op
BenchmarkGenericMap_Copy-12       633978              1758 ns/op            2324 B/op          1 allocs/op

@mariomac mariomac requested review from jotak and jpinsonneau October 14, 2022 09:44
Copy link
Collaborator

@jpinsonneau jpinsonneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should use make everytime it's possible right ? 🥇

@mariomac
Copy link
Author

@jpinsonneau if you know the approximate length of the resulting map, yes (same for slices).

If you don't know the length, doing m := map[string]string{} is commonly preferred.

@mariomac mariomac merged commit 4e957ce into netobserv:main Oct 14, 2022
@mariomac mariomac deleted the clone branch October 14, 2022 10:25
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.

2 participants