MCPcopy Index your code
hub / github.com/easierway/concurrent_map

github.com/easierway/concurrent_map @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
47 symbols 114 edges 8 files 15 documented · 32%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ConcurrentMap for GO

The better performance thread-safe map in GO

After v1.9, normally, programmers have two options for thread-safe map. One is to build the thread-safe solution with syn.RWMutex. But, in many cases, especially, in the case the number of CPU cores is larger than 2, this option's performance is quite poor.

Another is to use the sync.map, which has been added to the sync package from v.1.9. Unfortunately, sync.map can not work well for all the cases, especially, the case of multi-threads writing. For more info, please, check the great video https://www.youtube.com/watch?v=C1EtfDnsdDs.

This project is to provide a thread-safe map which is Java ConcurrentMap's GO version. From the following benchmark you can see it is better in the multi-thread writing cases.

The following test is about 100 Goroutines writing and 100 Groutines reading. The test is executed on Macbook (macOS 10.13.2, 2 core (2.3G Intel Core i5), 8G LPDDR3)

image

FAQ

1 Why not provide the default hash function for partition?

Ans: As you known, the partition solution would impact the performance significantly. The proper partition solution balances the access to the different partitions and avoid of the hot partition. The access mode highly relates to your business. So, the better partition solution would just be designed according to your business.

Extension points exported contracts — how you extend this code

Map (Interface)
(no doc) [4 implementers]
map_benchmark_test.go
Partitionable (Interface)
Partitionable is the interface which should be implemented by key type. It is to define how to partition the entries. [2 …
concurrent_map.go

Core symbols most depended-on inside this repo

StrKey
called by 10
string_key.go
Get
called by 9
map_benchmark_test.go
Set
called by 6
map_benchmark_test.go
I64Key
called by 5
int64_key.go
Del
called by 4
map_benchmark_test.go
CreateConcurrentMap
called by 4
concurrent_map.go
Value
called by 3
concurrent_map.go
getPartition
called by 3
concurrent_map.go

Shape

Method 25
Function 13
Struct 7
Interface 2

Languages

Go100%

Modules by API surface

concurrent_map.go14 symbols
map_benchmark_test.go6 symbols
sync_map_benchmark_adapter.go5 symbols
string_key.go5 symbols
rwlock_map_benchmark_adapter.go5 symbols
concurrent_map_benchmark_adapter.go5 symbols
int64_key.go4 symbols
concurrent_map_test.go3 symbols

For agents

$ claude mcp add concurrent_map \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact