explaingit

orcaman/concurrent-map

4,529GoAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A Go package that provides a fast, thread-safe key-value map for programs running multiple tasks at once, outperforming Go's built-in concurrent map in high-update scenarios.

Mindmap

mindmap
  root((concurrent-map))
    What it does
      Thread-safe map
      Concurrent access
      Sharded storage
    Tech Stack
      Go
    Use Cases
      In-memory cache
      Concurrent services
      High-write stores
    API
      Set values
      Get values
      Remove entries
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace Go's built-in map in any service that handles concurrent reads and writes from multiple goroutines

USE CASE 2

Build a high-throughput in-memory cache where many requests update the same data store simultaneously

USE CASE 3

Use as a better alternative to sync.Map when your app constantly updates and removes entries rather than just adding new ones

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min
Use, modify, and distribute freely for any purpose including commercial use, as long as you keep the copyright notice.

In plain English

When a program runs multiple tasks at the same time (called concurrency), those tasks sometimes try to read from and write to the same data structure simultaneously. Go's built-in map type, which is a basic key-value store, is not safe for this kind of simultaneous access. If two tasks try to modify it at the same time, the program can crash or produce wrong results. This repository provides a replacement map that is safe for concurrent use. It achieves good performance by splitting the data across multiple internal shards, so different tasks can often work on different shards at the same time without waiting on each other. This reduces the time tasks spend blocking, compared to a single lock that would stop all activity. Go's standard library added its own concurrent map type called sync.Map in version 1.9, but that version is designed mainly for scenarios where you mostly add new keys and rarely update existing ones. If your program behaves more like a small in-memory database, constantly updating and removing entries, this library is a better fit. The API is straightforward and closely mirrors what Go developers already know from using regular maps. You create a new map, call Set to store a value, Get to retrieve it, and Remove to delete it. The package is imported under the name cmap, and you install it with the standard Go toolchain command. The project is MIT-licensed and accepts contributions. The maintainers ask that contributors open an issue first to describe the change, include tests with any new code, and keep the library as simple and close to the native map behavior as possible.

Copy-paste prompts

Prompt 1
Show me how to use concurrent-map in Go to safely share a key-value store between multiple goroutines with Set, Get, and Remove
Prompt 2
I have a Go web server where multiple request handlers write to the same map, show me how to switch to concurrent-map (cmap)
Prompt 3
What is the difference between concurrent-map and Go's sync.Map, and when should I choose one over the other?
Prompt 4
Give me a Go example using cmap that stores user session data and handles concurrent reads and deletes safely
Open on GitHub → Explain another repo

← orcaman on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.