Home >Backend Development >Golang >ShrinkMap - A High-Performance Concurrent Map with Automatic Memory Management for Go

ShrinkMap - A High-Performance Concurrent Map with Automatic Memory Management for Go

Barbara Streisand
Barbara StreisandOriginal
2024-11-03 21:05:03223browse

ShrinkMap - A High-Performance Concurrent Map with Automatic Memory Management for Go

ShrinkMap - A High-Performance Concurrent Map with Automatic Memory Management for Go

Hello Gophers! ?

I'm excited to share ShrinkMap, a new concurrent map implementation for Go that focuses on automatic memory management and performance.

https://github.com/jongyunha/shrinkmap/

What is ShrinkMap?

ShrinkMap is a thread-safe map implementation that automatically manages memory by cleaning up unused entries while maintaining high performance for concurrent operations. It's designed to be a drop-in replacement for sync.Map when you need better memory efficiency.

Key Features

  • Automatic Memory Management: Automatically removes unused entries to prevent memory leaks
  • Thread-Safe: Fully concurrent-safe operations with minimal lock contention
  • High Performance: Optimized for both read and write operations
  • Type-Safe: Fully generic implementation (Go 1.18 )
  • Simple API: Familiar interface similar to sync.Map

Quick Example

package main

import (
    "fmt"
    "github.com/jongyunha/shrinkmap"
)

func main() {
    // Create a new map
    sm := shrinkmap.New[string, int]()

    // Store values
    sm.Store("counter", 1)

    // Load values
    if val, ok := sm.Load("counter"); ok {
        fmt.Printf("Value: %d\n", val)
    }
}

Why ShrinkMap?

While sync.Map is great for many use cases, there are scenarios where memory management becomes crucial:

  • Long-running applications with dynamic key-value pairs
  • Systems with memory constraints
  • Applications with high churn in map entries
  • Cases where manual cleanup is error-prone or impractical

Project Status

  • GitHub Repository: https://github.com/jongyunha/shrinkmap
  • License: MIT
  • Go Version: 1.18

Looking for Feedback

I'd love to hear your thoughts and feedback on:

  1. The overall approach to memory management
  2. API design and usability
  3. Performance in real-world scenarios
  4. Additional features you'd like to see

Contributing

The project is open for contributions! Whether it's bug reports, feature requests, or code contributions, all are welcome.

Feel free to:

  • Star the repository if you find it useful
  • Open issues for bugs or feature requests
  • Submit PRs for improvements
  • Share your use cases and feedback

Looking forward to your feedback and suggestions!

The above is the detailed content of ShrinkMap - A High-Performance Concurrent Map with Automatic Memory Management for Go. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn