{"id":37188551,"url":"https://github.com/jongyunha/shrinkmap","last_synced_at":"2026-01-14T21:55:53.644Z","repository":{"id":260579544,"uuid":"881738237","full_name":"jongyunha/shrinkmap","owner":"jongyunha","description":"ShrinkableMap is a high-performance, generic, thread-safe map implementation for Go that automatically manages memory by shrinking its internal storage when items are deleted. It provides a solution to the common issue where Go's built-in maps don't release memory after deleting elements.","archived":false,"fork":false,"pushed_at":"2025-07-09T03:46:22.000Z","size":64,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T21:47:30.873Z","etag":null,"topics":["go","map","memory","shrink","shrinkmap"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jongyunha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-01T05:52:33.000Z","updated_at":"2025-07-09T13:58:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"15c85934-838f-4437-a282-14922efc2a51","html_url":"https://github.com/jongyunha/shrinkmap","commit_stats":null,"previous_names":["jongyunha/shrinkmap"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jongyunha/shrinkmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongyunha%2Fshrinkmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongyunha%2Fshrinkmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongyunha%2Fshrinkmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongyunha%2Fshrinkmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jongyunha","download_url":"https://codeload.github.com/jongyunha/shrinkmap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongyunha%2Fshrinkmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","map","memory","shrink","shrinkmap"],"created_at":"2026-01-14T21:55:52.818Z","updated_at":"2026-01-14T21:55:53.635Z","avatar_url":"https://github.com/jongyunha.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ShrinkableMap\n\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/jongyunha/shrinkmap.svg)](https://pkg.go.dev/github.com/jongyunha/shrinkmap)\n[![Go Report Card](https://goreportcard.com/badge/github.com/jongyunha/shrinkmap)](https://goreportcard.com/report/github.com/jongyunha/shrinkmap)\n[![Coverage Status](https://coveralls.io/repos/github/jongyunha/shrinkmap/badge.svg?branch=main)](https://coveralls.io/github/jongyunha/shrinkmap?branch=main)\n\nShrinkableMap is a high-performance, generic, thread-safe map implementation for Go that automatically manages memory by shrinking its internal storage when items are deleted. It addresses the common issue where Go's built-in maps don't release memory after deleting elements.\n\n## 🚀 Features\n\n- **Type Safety**\n    - Generic type support for compile-time type checking\n    - Type-safe operations for all map interactions\n\n- **Performance**\n    - Optimized concurrent access with minimal locking\n    - Efficient atomic operations for high throughput\n    - Batch operations for improved performance\n\n- **Memory Management**\n    - Automatic memory shrinking with configurable policies\n    - Advanced concurrent shrinking behavior\n    - Memory-efficient iterators\n\n- **Reliability**\n    - Thread-safe implementation\n    - Panic recovery and error tracking\n    - Comprehensive metrics collection\n\n- **Developer Experience**\n    - Safe iteration with snapshot support\n    - Batch operations for bulk processing\n    - Clear error reporting and metrics\n    - Zero external dependencies\n    - Production-ready with extensive tests\n\n## 📦 Installation\n\n```bash\ngo get github.com/jongyunha/shrinkmap\n```\n\n## 🔧 Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/jongyunha/shrinkmap\"\n)\n\nfunc main() {\n    // Create a new map with default configuration\n    sm := shrinkmap.New[string, int](shrinkmap.DefaultConfig())\n    defer sm.Stop()\n\n    // Basic operations\n    sm.Set(\"one\", 1)\n    sm.Set(\"two\", 2)\n\n    if value, exists := sm.Get(\"one\"); exists {\n        fmt.Printf(\"Value: %d\\n\", value)\n    }\n\n    // Delete value\n    sm.Delete(\"one\")\n}\n```\n\n## 💡 Advanced Usage\n\n### Batch Operations\n\nEfficiently process multiple operations atomically:\n\n```go\nbatch := shrinkmap.BatchOperations[string, int]{\n    Operations: []shrinkmap.BatchOperation[string, int]{\n        {Type: shrinkmap.BatchSet, Key: \"one\", Value: 1},\n        {Type: shrinkmap.BatchSet, Key: \"two\", Value: 2},\n        {Type: shrinkmap.BatchDelete, Key: \"three\"},\n    },\n}\n\n// Apply all operations atomically\nsm.ApplyBatch(batch)\n```\n\n### Safe Iteration\n\nIterate over map contents safely using the iterator:\n\n```go\n// Create an iterator\niter := sm.NewIterator()\n\n// Iterate over all items\nfor iter.Next() {\n    key, value := iter.Get()\n    fmt.Printf(\"Key: %v, Value: %v\\n\", key, value)\n}\n\n// Or use snapshot for bulk processing\nsnapshot := sm.Snapshot()\nfor _, kv := range snapshot {\n    fmt.Printf(\"Key: %v, Value: %v\\n\", kv.Key, kv.Value)\n}\n```\n\n### Performance Monitoring\n\nTrack performance metrics:\n\n```go\nmetrics := sm.GetMetrics()\nfmt.Printf(\"Total operations: %d\\n\", metrics.TotalItemsProcessed())\nfmt.Printf(\"Peak size: %d\\n\", metrics.PeakSize())\nfmt.Printf(\"Total shrinks: %d\\n\", metrics.TotalShrinks())\n```\n\n## 🔍 Configuration Options\n\n```go\nconfig := shrinkmap.Config{\n    InitialCapacity:      1000,\n    AutoShrinkEnabled:    true,\n    ShrinkInterval:       time.Second,\n    MinShrinkInterval:    time.Second,\n    ShrinkRatio:         0.5,\n    CapacityGrowthFactor: 1.5,\n    MaxMapSize:           1000000,\n}\n```\n\n## 🛡️ Thread Safety Guarantees\n\n- All map operations are atomic and thread-safe\n- Safe concurrent access from multiple goroutines\n- Thread-safe batch operations\n- Safe iteration with consistent snapshots\n- Coordinated shrinking operations\n- Thread-safe metrics collection\n\n## 📊 Performance\n\nBenchmark results on typical operations (Intel i7-9700K, 32GB RAM):\n\n```\nBenchmarkBasicOperations/Sequential_Set-8         5000000    234 ns/op\nBenchmarkBasicOperations/Sequential_Get-8         10000000   112 ns/op\nBenchmarkBatchOperations/BatchSize_100-8         100000     15234 ns/op\nBenchmarkConcurrency/Parallel_8-8                1000000    1123 ns/op\n```\n\n## 📝 Best Practices\n\n1. **Resource Management**\n```go\nsm := shrinkmap.New[string, int](config)\ndefer sm.Stop() // Always ensure proper cleanup\n```\n\n2. **Batch Processing**\n```go\n// Use batch operations for multiple updates\nbatch := prepareBatchOperations()\nsm.ApplyBatch(batch)\n```\n\n3. **Safe Iteration**\n```go\n// Use iterator for safe enumeration\niter := sm.NewIterator()\nfor iter.Next() {\n    // Process items safely\n}\n```\n\n## 🗓️ Version History\n\n### v0.0.4 (Current)\n- Added batch operations support for atomic updates\n- Implemented safe iterator pattern\n- Enhanced performance for bulk operations\n- Added comprehensive benchmarking suite\n- Improved documentation and examples\n\n### history\n#### v0.0.3\n- enhanced performance and memory management\n#### v0.0.2\n- Added error tracking and panic recovery\n- Added state snapshot functionality\n- Added graceful shutdown\n- Enhanced metrics collection\n- Improved resource cleanup\n#### v0.0.1\n- Initial release with core functionality\n- Thread-safe implementation\n- Automatic shrinking support\n- Generic type support\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\nMade with ❤️ by [Jongyun Ha](https://github.com/jongyunha)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongyunha%2Fshrinkmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjongyunha%2Fshrinkmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongyunha%2Fshrinkmap/lists"}