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

Map/MapOf.Range iteration order #125

Open
mdogan opened this issue Mar 22, 2024 · 1 comment
Open

Map/MapOf.Range iteration order #125

mdogan opened this issue Mar 22, 2024 · 1 comment
Labels
enhancement New feature or request question Further information is requested

Comments

@mdogan
Copy link

mdogan commented Mar 22, 2024

Map in the standard Go library (afaik even sync.Map) has an indeterministic iteration order. On each iteration a random point is chosen. They have various reasons for that, performance (golang/go#8412) or preventing bad codes relying on fixed iteration order.

Currently Map/MapOf.Range methods have a fixed iteration order for a stable map. Would you consider applying some randomness similar to standard library? For example starting from a random bucket instead of the first bucket.

@puzpuzpuz puzpuzpuz added enhancement New feature or request question Further information is requested labels Mar 22, 2024
@puzpuzpuz
Copy link
Owner

In case of xsync, such randomization won't improve performance, but preventing bad code relying on fixed iteration order may be valuable for someone. Let me keep this issue around and see if anyone else requests it.

The implementation could be as simple as starting the iteration with a randomly selected bucket.

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

No branches or pull requests

2 participants