{"id":13817225,"url":"https://github.com/a8m/syncmap","last_synced_at":"2025-07-22T14:36:09.770Z","repository":{"id":39969508,"uuid":"184604635","full_name":"a8m/syncmap","owner":"a8m","description":"A typed implementation of the Go sync.Map using code generation","archived":false,"fork":false,"pushed_at":"2023-02-25T07:42:34.000Z","size":41,"stargazers_count":256,"open_issues_count":5,"forks_count":18,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-26T09:43:39.816Z","etag":null,"topics":["code-generation","concurrent-map","generics","go","map","sync","syncmap"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a8m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-05-02T15:20:57.000Z","updated_at":"2025-05-21T05:00:09.000Z","dependencies_parsed_at":"2024-06-18T22:43:37.004Z","dependency_job_id":"9bb4d824-d954-4f36-a7ea-3cf9d725a2b5","html_url":"https://github.com/a8m/syncmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/a8m/syncmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fsyncmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fsyncmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fsyncmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fsyncmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a8m","download_url":"https://codeload.github.com/a8m/syncmap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a8m%2Fsyncmap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266510809,"owners_count":23940714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["code-generation","concurrent-map","generics","go","map","sync","syncmap"],"created_at":"2024-08-04T06:00:37.514Z","updated_at":"2025-07-22T14:36:09.749Z","avatar_url":"https://github.com/a8m.png","language":"Go","readme":"# syncmap \n![https://godoc.org/github.com/a8m/syncmap](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)\n![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)\n[![Build Status](https://travis-ci.com/a8m/syncmap.svg?token=ckAPcX3LvhP9wJPS6sgW\u0026branch=master)](https://travis-ci.com/a8m/syncmap)\n[![Go Report Card](https://goreportcard.com/badge/github.com/a8m/syncmap)](https://goreportcard.com/report/github.com/a8m/syncmap)\n\nA __typed__ implementation of the Go `sync.Map` using code generation. \n\n### Install\n\n```\ngo get -u github.com/a8m/syncmap@master\n```\n\n### Examples:\n\n1. Using CLI\n  ```bash\n  $ syncmap -name IntMap \"map[int]int\"\n  $ syncmap -name RequestMap -pkg mypkg \"map[string]*http.Request\"\n  ```\n  Or:\n  ```bash\n  $ go run github.com/a8m/syncmap -name IntMap \"map[int]int\"\n  ```\n  \n2. Using `go generate`.\n    \n   - Add a directive with map definition:\n     ```go\n     //go:generate go run github.com/a8m/syncmap -name WriterMap map[string]io.Writer\n   \n     //go:generate go run github.com/a8m/syncmap -name Requests map[string]*http.Request\n     ```\n   - Then, run `go generate` on this package. \n\n   See [testdata/gen.go](https://github.com/a8m/syncmap/blob/master/testdata/gen.go) for more examples.\n   \n### How does it work?\n\n`syncmap` didn't copy the code of `sync/map.go` and replace its identifiers. Instead, it reads the `sync/map.go` from\nyour `GOROOT`, parses it into an `*ast.File`, and runs a few mutators that bring it to the desired state.\nCheck the [code](https://github.com/a8m/syncmap/blob/master/syncmap.go#L91) for more information.\n\n__How can we make sure it will continue to work?__ - I'm running a daily CI test on _TravisCI_.\n   \n### Benchmark\nBenchmark tests were taken from the `sync` package.\n```\nBenchmarkLoadMostlyHits/*main.DeepCopyMap-8         \t100000000\t        15.1 ns/op\nBenchmarkLoadMostlyHits/*main.RWMutexMap-8          \t30000000\t        54.4 ns/op\nBenchmarkLoadMostlyHits/*sync.Map-8                 \t100000000\t        14.0 ns/op\nBenchmarkLoadMostlyHits/*main.IntMap-8              \t300000000\t        5.65 ns/op \u003c--\n\nBenchmarkLoadMostlyMisses/*main.DeepCopyMap-8       \t200000000\t        10.2 ns/op\nBenchmarkLoadMostlyMisses/*main.RWMutexMap-8        \t30000000\t        59.2 ns/op\nBenchmarkLoadMostlyMisses/*sync.Map-8               \t100000000\t        11.3 ns/op\nBenchmarkLoadMostlyMisses/*main.IntMap-8            \t300000000\t        4.05 ns/op \u003c--\n\nBenchmarkLoadOrStoreBalanced/*main.RWMutexMap-8     \t 3000000\t        400 ns/op\nBenchmarkLoadOrStoreBalanced/*sync.Map-8            \t 3000000\t        400 ns/op\nBenchmarkLoadOrStoreBalanced/*main.IntMap-8         \t 5000000\t        233 ns/op \u003c--\n\nBenchmarkLoadOrStoreUnique/*main.RWMutexMap-8       \t 2000000\t        744 ns/op\nBenchmarkLoadOrStoreUnique/*sync.Map-8              \t 2000000\t        903 ns/op\nBenchmarkLoadOrStoreUnique/*main.IntMap-8           \t 3000000\t        388 ns/op \u003c--\n\nBenchmarkLoadOrStoreCollision/*main.DeepCopyMap-8   \t200000000\t        7.29 ns/op\nBenchmarkLoadOrStoreCollision/*main.RWMutexMap-8    \t20000000\t        97.5 ns/op\nBenchmarkLoadOrStoreCollision/*sync.Map-8           \t200000000\t        9.11 ns/op\nBenchmarkLoadOrStoreCollision/*main.IntMap-8        \t500000000\t        3.14 ns/op \u003c--\n\nBenchmarkRange/*main.DeepCopyMap-8                  \t  500000\t        4479 ns/op\nBenchmarkRange/*main.RWMutexMap-8                   \t   30000\t        56834 ns/op\nBenchmarkRange/*sync.Map-8                          \t  300000\t        4464 ns/op\nBenchmarkRange/*main.IntMap-8                       \t1000000000\t        2.38 ns/op \u003c--\n\nBenchmarkAdversarialAlloc/*main.DeepCopyMap-8       \t 2000000\t        826 ns/op\nBenchmarkAdversarialAlloc/*main.RWMutexMap-8        \t20000000\t        73.6 ns/op\nBenchmarkAdversarialAlloc/*sync.Map-8               \t 5000000\t        303 ns/op\nBenchmarkAdversarialAlloc/*main.IntMap-8            \t10000000\t        182 ns/op \u003c--\n\nBenchmarkAdversarialDelete/*main.DeepCopyMap-8      \t10000000\t        204 ns/op\nBenchmarkAdversarialDelete/*main.RWMutexMap-8       \t20000000\t        78.3 ns/op\nBenchmarkAdversarialDelete/*sync.Map-8              \t20000000\t        72.2 ns/op\nBenchmarkAdversarialDelete/*main.IntMap-8           \t100000000\t        14.2 ns/op \u003c--\n```\n\nRunning benchmark with `-benchmem`\n```\nBenchmarkLoadMostlyHits/*main.DeepCopyMap-8         100000000\t  12.7 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyHits/*main.RWMutexMap-8          30000000\t  53.6 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyHits/*sync.Map-8                 100000000\t  16.3 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyHits/*main.IntMap-8              200000000\t  6.02 ns/op\t  0 B/op\t  0 allocs/op \u003c--\n\nBenchmarkLoadMostlyMisses/*main.DeepCopyMap-8       200000000\t  7.99 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyMisses/*main.RWMutexMap-8        30000000\t  52.6 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyMisses/*sync.Map-8               200000000\t  8.87 ns/op\t  7 B/op\t  0 allocs/op\nBenchmarkLoadMostlyMisses/*main.IntMap-8            1000000000\t  2.88 ns/op\t  0 B/op\t  0 allocs/op \u003c--\n\nBenchmarkLoadOrStoreBalanced/*main.RWMutexMap-8     3000000\t  357 ns/op\t  71 B/op\t  2 allocs/op\nBenchmarkLoadOrStoreBalanced/*sync.Map-8            3000000\t  417 ns/op\t  70 B/op\t  3 allocs/op\nBenchmarkLoadOrStoreBalanced/*main.IntMap-8         5000000\t  202 ns/op\t  42 B/op\t  1 allocs/op \u003c--\n\nBenchmarkLoadOrStoreUnique/*main.RWMutexMap-8       2000000\t  648 ns/op\t  178 B/op\t  2 allocs/op\nBenchmarkLoadOrStoreUnique/*sync.Map-8              2000000\t  745 ns/op\t  163 B/op\t  4 allocs/op\nBenchmarkLoadOrStoreUnique/*main.IntMap-8           3000000\t  368 ns/op\t  74 B/op\t  2 allocs/op \u003c--\n\nBenchmarkLoadOrStoreCollision/*main.DeepCopyMap-8   300000000\t  5.90 ns/op\t  0 B/op\t  0 allocs/op\nBenchmarkLoadOrStoreCollision/*main.RWMutexMap-8    20000000\t  94.5 ns/op\t  0 B/op\t  0 allocs/op\nBenchmarkLoadOrStoreCollision/*sync.Map-8           200000000\t  7.55 ns/op\t  0 B/op\t  0 allocs/op\nBenchmarkLoadOrStoreCollision/*main.IntMap-8        1000000000\t  2.68 ns/op\t  0 B/op\t  0 allocs/op \u003c--\n\nBenchmarkRange/*main.DeepCopyMap-8                  500000\t  3376 ns/op\t  0 B/op\t  0 allocs/op\nBenchmarkRange/*main.RWMutexMap-8                   30000\t  56675 ns/op\t  16384 B/op\t  1 allocs/op\nBenchmarkRange/*sync.Map-8                          500000\t  3587 ns/op\t  0 B/op\t  0 allocs/op\nBenchmarkRange/*main.IntMap-8                       2000000000\t  1.75 ns/op\t  0 B/op\t  0 allocs/op \u003c--\n\nBenchmarkAdversarialAlloc/*main.DeepCopyMap-8       2000000\t  761 ns/op\t  535 B/op\t  1 allocs/op\nBenchmarkAdversarialAlloc/*main.RWMutexMap-8        20000000\t  67.9 ns/op\t  8 B/op\t  1 allocs/op\nBenchmarkAdversarialAlloc/*sync.Map-8               5000000\t  264 ns/op\t  51 B/op\t  1 allocs/op\nBenchmarkAdversarialAlloc/*main.IntMap-8            10000000\t  176 ns/op\t  28 B/op\t  0 allocs/op \u003c--\n\nBenchmarkAdversarialDelete/*main.DeepCopyMap-8      10000000\t  194 ns/op\t  168 B/op\t  1 allocs/op\nBenchmarkAdversarialDelete/*main.RWMutexMap-8       20000000\t  76.9 ns/op\t  25 B/op\t  1 allocs/op\nBenchmarkAdversarialDelete/*sync.Map-8              20000000\t  60.8 ns/op\t  18 B/op\t  1 allocs/op\nBenchmarkAdversarialDelete/*main.IntMap-8           100000000\t  13.1 ns/op\t  0 B/op\t  0 allocs/op \u003c--\n```\n\n\n## LICENSE\nI am providing code in the repository to you under MIT license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook)\n\n","funding_links":[],"categories":["Misc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fsyncmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa8m%2Fsyncmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa8m%2Fsyncmap/lists"}