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
MapOf: Generic Keys #46
Conversation
01c7900
to
12e0ac8
Compare
12e0ac8
to
dc1df69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I'd like to address the second consideration from #17 (comment) before merging this one. I'm going to address it, but probably not in the nearest term. Will post an update here once it's done.
No worries, just throwing this up for discussion. No pressure to merge :) |
It's worth noting that I'm seeing VERY poor performance for certain keys. This could be an issue I've introduced here, or it could be that the string hashes were just unlikely to generate problematic keys. Here's an example that's very problematic on my machine (Apple M1 Pro): // Benchmark32768000000/xsync.Map-8 142 20367105 ns/op
// Benchmark32768000000/sync.Map-8 4306820 385.9 ns/op
func Benchmark32768000000(b *testing.B) {
b.Run("xsync.Map", func(b *testing.B) {
m := NewIntegerMapOf[uint64, int]()
for i := 0; i < b.N; i++ {
m.Store(uint64(i*32768000000), 0)
}
})
b.Run("sync.Map", func(b *testing.B) {
m := sync.Map{}
for i := 0; i < b.N; i++ {
m.Store(uint64(i*32768000000), 0)
}
})
}
// Benchmark32768000001/xsync.Map-8 21440982 48.54 ns/op
// Benchmark32768000001/sync.Map-8 4475781 385.2 ns/op
func Benchmark32768000001(b *testing.B) {
b.Run("xsync.Map", func(b *testing.B) {
m := NewIntegerMapOf[uint64, int]()
for i := 0; i < b.N; i++ {
m.Store(uint64(i*32768000001), 0)
}
})
b.Run("sync.Map", func(b *testing.B) {
m := sync.Map{}
for i := 0; i < b.N; i++ {
m.Store(uint64(i*32768000001), 0)
}
})
} |
@iamcalledrob I've just merged #48, so this PR should be unblocked at last. Sorry for taking that long. 🥲 Let me know if you're willing to give another try with this PR, otherwise I'll pick it up myself. |
This is very likely due to hash collisions and #48 should make this problem less significant. The problem with The proper way to get rid of the problem is to apply |
Closing this one in favor of #49 to speed up things. @iamcalledrob many thanks for your contribution! |
Support for generic keys, and an accompanying hasher func, as discussed in #17
This shouldn't be a breaking change for function calls, but since the MapOf type has changed from
type MapOf[V any] struct
totype MapOf[K, V any] struct
, this isn't a fully backwards-compatible change.Usage:
Benchmarks are unchanged