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

Copy on write map #114

Open
jorgebay opened this issue Nov 16, 2023 · 3 comments
Open

Copy on write map #114

jorgebay opened this issue Nov 16, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@jorgebay
Copy link

(First of all, cool project @puzpuzpuz! A faster and typed concurrent map like MapOf is something that should be part of go's stdlib)

Copy-on-write maps are useful for read-mostly performance-critical areas, as LoadOrCompute() calls only cost an atomic load for reads. Additionally, these semantics provide a snapshot view that allow fast and predictable iteration.

Typical use cases for these structures are config settings and topology management.

I can contribute it, if you think it belongs in this project.

@puzpuzpuz puzpuzpuz added the enhancement New feature or request label Nov 16, 2023
@puzpuzpuz
Copy link
Owner

Hi Jorge,

I'm all for a contribution. COW data structures are on the radar and I have a COW list issue open (#27), but there wasn't enough interest for it, unfortunately. In MapOf, LoadOrCompute()'s read path assumes two atomic loads in the best case. So the end COW map performance might be close to MapOf, but it's certainly worth exploring.

@jorgebay
Copy link
Author

I agree that the improvement on the performance side for read-mostly cases is minor.

I think the main benefit is related to the consistent snapshot semantics: iterate a point-in-time structure, e.g., if you have a map with [a, b, c] keys that get mutated into [a, b, d, e] the caller will never get [a, b, d].

@puzpuzpuz
Copy link
Owner

I think the main benefit is related to the consistent snapshot semantics

Yes, that's not possible with non-COW or single mutex protected data structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants