Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: reduce (*Map).Load penalty for Stores with new keys #21032

Open
bcmills opened this issue Jul 16, 2017 · 1 comment
Open

sync: reduce (*Map).Load penalty for Stores with new keys #21032

bcmills opened this issue Jul 16, 2017 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Jul 16, 2017

In the Go 1.9 implementation of sync.Map, storing any new key in the map causes Load calls on all new keys to acquire a mutex until enough misses have occurred to promote the read-write map again.

That's probably fine for append-only maps (such as the sync.Map uses in the standard library), because it goes away in the steady state. However, it's problematic for use in caches, where there may be frequent Load and Store calls for keys that miss the cache.

I suspect we could substantially reduce the Load penalty by using a Bloom or HyperLogLog filter instead of a simple boolean to store the set of new keys: a Load that misses in the read-only map would still have more cache misses due to writes to the filter, but it would no longer block Store calls or contend with other Loads.

@bcmills
Copy link
Contributor Author

bcmills commented Jul 16, 2017

(@odeke-em and @RLH both made suggestions along these lines.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

4 participants