https://github.com/snawoot/lfmap
Generic concurrent lock-free map for Golang
https://github.com/snawoot/lfmap
concurrent-data-structure concurrent-map lock-free lock-free-map map
Last synced: 16 days ago
JSON representation
Generic concurrent lock-free map for Golang
- Host: GitHub
- URL: https://github.com/snawoot/lfmap
- Owner: Snawoot
- License: mit
- Created: 2024-08-25T14:45:40.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-08-31T23:40:40.000Z (8 months ago)
- Last Synced: 2025-03-27T13:51:26.643Z (about 1 month ago)
- Topics: concurrent-data-structure, concurrent-map, lock-free, lock-free-map, map
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 44
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lfmap
[](https://pkg.go.dev/github.com/Snawoot/lfmap)
Generic concurrent lock-free map for Golang.
Key features:
* `range` iteration over consistent snapshot of map without locking other threads and without copying all data in map to maintain that snapshot.
* Convenient [transactions](https://pkg.go.dev/github.com/Snawoot/lfmap#Map.Transaction) where you can read-write multiple keys, check some conditions and make a change based on your logic. Compared to lfmap, `sync.Map` allows only CAS operations against single key and that's it.## Usage
See [godoc examples](https://pkg.go.dev/github.com/Snawoot/lfmap#pkg-examples).
## Benchmarks
```
goos: linux
goarch: amd64
pkg: github.com/Snawoot/lfmap
cpu: Intel(R) N100
BenchmarkLFMapSet-4 165698 11190 ns/op
BenchmarkSyncMapSet-4 857448 2302 ns/op
BenchmarkLFMapGet-4 3221922 365.1 ns/op
BenchmarkSyncMapGet-4 5302554 189.9 ns/op
BenchmarkLFMapRange1000000-4 8 142530076 ns/op
BenchmarkSyncMapRange1000000-4 7 150277709 ns/op
PASS
ok github.com/Snawoot/lfmap 31.614s
```So far lfmap is 2-6 times slower than `sync.Map`, mostly because of underlying immutable ds performance. However, nice transactional properties may make it useful.