susheel chaudhary
susheel chaudhary

Reputation: 271

what is the performance impact of golang maps

In golang, maps implemented using hash tables .I am using locks of sync package for readinng and writing in maps. Is there any performance impact if 50,000 reqests try to access the map ? What is the order of reading/writing maps? Is it O(1)?

Upvotes: 2

Views: 13882

Answers (1)

Elazar Leibovich
Elazar Leibovich

Reputation: 33593

There are two separate issues here:

  1. What is the performance of a Go map?

An answer can be found in this issue

  1. What are the performance implication of 50,000 goroutines contending on a map.

This doesn't sound like a good idea, but you can never know without benchmarking. You might want to consider sending the map values asynchronously through a buffered channel, if you don't depend on the fact that the map value would be written immediately.

You might also want to check out concurrent-map which is solving a similar problem.

Upvotes: 6

Related Questions