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

concurrent-map key interface{} support #55

Open
ross-oreto opened this issue May 11, 2017 · 5 comments
Open

concurrent-map key interface{} support #55

ross-oreto opened this issue May 11, 2017 · 5 comments

Comments

@ross-oreto
Copy link

Enhancement:
If concurrent-map is supposed to behave the same as the plain map, then the allowed key types should be the same and the type map[interface{}]interface{} should be supported.

@orcaman
Copy link
Owner

orcaman commented May 17, 2017

Hi @ross-oreto

You have a point there. There is obviously a trade-off between allowing arbitrary key types to the map's performance, and perhaps a usability issue as well (it may be annoying to type convert). Would be interesting to benchmark such an implementation. Would be cool if you could try to make this change on your own dev branch and benchmark it. If you end up doing so please update. Otherwise I'll leave this hanging for a while and close it.

@ross-oreto
Copy link
Author

Baseline:
BenchmarkItems-4 300 4808352 ns/op 1949388 B/op 735 allocs/op
BenchmarkMarshalJson-4 100 13807963 ns/op 3298981 B/op 30961 allocs/op
BenchmarkStrconv-4 30000000 55.6 ns/op 7 B/op 1 allocs/op
BenchmarkSingleInsertAbsent-4 2000000 779 ns/op 183 B/op 2 allocs/op
BenchmarkSingleInsertPresent-4 10000000 133 ns/op 16 B/op 1 allocs/op
BenchmarkMultiInsertDifferent_1_Shard-4 1000000 2348 ns/op 327 B/op 11 allocs/op
BenchmarkMultiInsertDifferent_16_Shard-4 1000000 2424 ns/op 327 B/op 11 allocs/op
BenchmarkMultiInsertDifferent_32_Shard-4 1000000 2263 ns/op 327 B/op 11 allocs/op
BenchmarkMultiInsertDifferent_256_Shard-4 500000 3006 ns/op 340 B/op 12 allocs/op
BenchmarkMultiInsertSame-4 1000000 1447 ns/op 160 B/op 10 allocs/op
BenchmarkMultiGetSame-4 3000000 475 ns/op 0 B/op 0 allocs/op
BenchmarkMultiGetSetDifferent_1_Shard-4 500000 3034 ns/op 334 B/op 12 allocs/op
BenchmarkMultiGetSetDifferent_16_Shard-4 500000 3140 ns/op 334 B/op 12 allocs/op
BenchmarkMultiGetSetDifferent_32_Shard-4 500000 3077 ns/op 335 B/op 12 allocs/op
BenchmarkMultiGetSetDifferent_256_Shard-4 500000 2984 ns/op 340 B/op 12 allocs/op
BenchmarkMultiGetSetBlock_1_Shard-4 1000000 2229 ns/op 163 B/op 12 allocs/op
BenchmarkMultiGetSetBlock_16_Shard-4 1000000 2165 ns/op 163 B/op 12 allocs/op
BenchmarkMultiGetSetBlock_32_Shard-4 1000000 2057 ns/op 163 B/op 12 allocs/op
BenchmarkMultiGetSetBlock_256_Shard-4 1000000 1956 ns/op 163 B/op 12 allocs/op
BenchmarkKeys-4 1000 1867250 ns/op 329373 B/op 34 allocs/op

with interface{} key:
BenchmarkItems-4 300 5340246 ns/op 1950417 B/op 803 allocs/op
BenchmarkMarshalJson-4 300 5256855 ns/op 1950606 B/op 806 allocs/op
BenchmarkStrconv-4 30000000 55.5 ns/op 7 B/op 1 allocs/op
BenchmarkSingleInsertAbsent-4 1000000 1087 ns/op 207 B/op 4 allocs/op
BenchmarkSingleInsertPresent-4 5000000 295 ns/op 35 B/op 3 allocs/op
BenchmarkMultiInsertDifferent_1_Shard-4 500000 4415 ns/op 561 B/op 31 allocs/op
BenchmarkMultiInsertDifferent_16_Shard-4 500000 4513 ns/op 561 B/op 31 allocs/op
BenchmarkMultiInsertDifferent_32_Shard-4 500000 4475 ns/op 562 B/op 31 allocs/op
BenchmarkMultiInsertDifferent_256_Shard-4 200000 6789 ns/op 771 B/op 52 allocs/op
BenchmarkMultiInsertSame-4 500000 3058 ns/op 352 B/op 30 allocs/op
BenchmarkMultiGetSame-4 500000 2323 ns/op 192 B/op 20 allocs/op
BenchmarkMultiGetSetDifferent_1_Shard-4 300000 7133 ns/op 770 B/op 52 allocs/op
BenchmarkMultiGetSetDifferent_16_Shard-4 200000 6709 ns/op 733 B/op 52 allocs/op
BenchmarkMultiGetSetDifferent_32_Shard-4 200000 6634 ns/op 733 B/op 52 allocs/op
BenchmarkMultiGetSetDifferent_256_Shard-4 300000 6790 ns/op 780 B/op 52 allocs/op
BenchmarkMultiGetSetBlock_1_Shard-4 300000 5743 ns/op 521 B/op 52 allocs/op
BenchmarkMultiGetSetBlock_16_Shard-4 300000 5622 ns/op 521 B/op 52 allocs/op
BenchmarkMultiGetSetBlock_32_Shard-4 300000 5567 ns/op 521 B/op 52 allocs/op
BenchmarkMultiGetSetBlock_256_Shard-4 300000 5493 ns/op 521 B/op 52 allocs/op
BenchmarkKeys-4 1000 2007344 ns/op 329577 B/op 54 allocs/op

@jalaziz
Copy link

jalaziz commented Jun 10, 2022

Would it be more feasible to implement this now with support for generics?

@khndhkx123
Copy link

@ross-oreto
Hi, how did you handle with Marshal Json ? BenchmarkMarshalJson-4 300 5256855 ns/op 1950606 B/op 806 allocs/op
I'm facing with Marshal Json error with interface{} type key. Got any idea or suggestion ?

@ross-oreto
Copy link
Author

@ross-oreto Hi, how did you handle with Marshal Json ? BenchmarkMarshalJson-4 300 5256855 ns/op 1950606 B/op 806 allocs/op I'm facing with Marshal Json error with interface{} type key. Got any idea or suggestion ?

I made changes locally necessary to use the interface key and ran those benchmarks, however I did not push my changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants