4

GitHub - mhmtszr/concurrent-swiss-map: A high-performance, thread-safe generic c...

 1 year ago
source link: https://github.com/mhmtszr/concurrent-swiss-map
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Concurrent Swiss Map

Concurrent Swiss Map is an open-source Go library that provides a high-performance, thread-safe generic concurrent hash map implementation designed to handle concurrent access efficiently. It's built with a focus on simplicity, speed, and reliability, making it a solid choice for scenarios where concurrent access to a hash map is crucial.

Uses dolthub/swiss map implementation under the hood.

Installation

Supports 1.18+ Go versions because of Go Generics

go get github.com/mhmtszr/concurrent-swiss-map

Usage

New functions will be added soon...

myMap := csmap.Create[int, string](
    csmap.WithShardCount[int, string](32), // default 32,
    csmap.WithCustomHasher[int, string](func(key int) uint64 {
        return 0
    }), // default maphash,
    csmap.WithSize[int, string](1000), // default 0
)
myMap.Store(10, "test")
myMap.Load(10)
myMap.Delete(10)
myMap.Has(10)
myMap.IsEmpty()
myMap.SetIfAbsent(10, "test")
myMap.Range(func(key int, value string) (stop bool) {})
myMap.Count()

Basic Architecture

img.png

Benchmark Test

Benchmark was made on:

  • Apple M1 Max
  • 32 GB memory

Benchmark test results can be obtained by running this file on local computers.

benchmark.png

Benchmark Results

  • Memory usage of the concurrent swiss map is better than other map implementations in all checked test scenarios.
  • In high concurrent systems, the concurrent swiss map is faster, but in systems containing few concurrent operations, it works similarly to RWMutexMap.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK