concurrent-map icon indicating copy to clipboard operation
concurrent-map copied to clipboard

[#136] Add custom shard count value in concurrent map

Open SeunghoonBaek opened this issue 2 years ago • 2 comments

#136

Hello, what I mentioned in the above issue page, I suggest to use custom shard count for each concurrent map instance. I would ask you please review this change and let me know how do you think about it? 😃

Thanks a lot!

(Please let me know if I should post more information before posting PR. :-) )

Benchmark result

> go test -bench=. -benchtime=10s -benchmem
goos: darwin
goarch: amd64
pkg: github.com/orcaman/concurrent-map/v2
cpu: Intel(R) Core(TM) i5-10600 CPU @ 3.30GHz
BenchmarkItems-12                                   5437           2329913 ns/op         1938390 B/op        417 allocs/op
BenchmarkItemsInteger-12                            5905           1957807 ns/op         1490132 B/op        485 allocs/op
BenchmarkItemsInt-12                                6870           1766993 ns/op         1336459 B/op        460 allocs/op
BenchmarkMarshalJson-12                             2079           5853171 ns/op         3125235 B/op      20438 allocs/op
BenchmarkStrconv-12                             458381920               30.00 ns/op           14 B/op          1 allocs/op
BenchmarkSingleInsertAbsent-12                  33966343               535.6 ns/op           161 B/op          1 allocs/op
BenchmarkSingleInsertAbsentSyncMap-12           17470662               927.0 ns/op           177 B/op          5 allocs/op
BenchmarkSingleInsertPresent-12                 237099622               49.44 ns/op            0 B/op          0 allocs/op
BenchmarkSingleInsertPresentSyncMap-12          164643420               73.08 ns/op           16 B/op          1 allocs/op
BenchmarkMultiInsertDifferentSyncMap-12          2763302              4833 ns/op             946 B/op         35 allocs/op
BenchmarkMultiInsertDifferent_1_Shard-12         4301349              3238 ns/op             317 B/op          2 allocs/op
BenchmarkMultiInsertDifferent_16_Shard-12       26476600               589.3 ns/op           144 B/op          2 allocs/op
BenchmarkMultiInsertDifferent_32_Shard-12       35410960               437.2 ns/op           186 B/op          2 allocs/op
BenchmarkMultiInsertDifferent_256_Shard-12      18891256               720.2 ns/op           217 B/op          4 allocs/op
BenchmarkMultiInsertSame-12                      4410878              2690 ns/op              16 B/op          1 allocs/op
BenchmarkMultiInsertSameSyncMap-12               3264914              4324 ns/op             552 B/op         31 allocs/op
BenchmarkMultiGetSame-12                        23550031               495.6 ns/op            16 B/op          1 allocs/op
BenchmarkMultiGetSameSyncMap-12                 52082953               238.2 ns/op            16 B/op          1 allocs/op
BenchmarkMultiGetSetDifferentSyncMap-12          2035042              6852 ns/op             959 B/op         37 allocs/op
BenchmarkMultiGetSetDifferent_1_Shard-12         3950667              4776 ns/op             437 B/op          5 allocs/op
BenchmarkMultiGetSetDifferent_16_Shard-12        5013445              2566 ns/op             221 B/op          4 allocs/op
BenchmarkMultiGetSetDifferent_32_Shard-12       15109965              2375 ns/op             255 B/op          4 allocs/op
BenchmarkMultiGetSetDifferent_256_Shard-12      18408936               722.6 ns/op           221 B/op          4 allocs/op
BenchmarkMultiGetSetBlockSyncMap-12             20848772               689.7 ns/op           544 B/op         32 allocs/op
BenchmarkMultiGetSetBlock_1_Shard-12             4526481              6174 ns/op             217 B/op          3 allocs/op
BenchmarkMultiGetSetBlock_16_Shard-12            6353364              2003 ns/op              68 B/op          2 allocs/op
BenchmarkMultiGetSetBlock_32_Shard-12           11579113              1180 ns/op              66 B/op          2 allocs/op
BenchmarkMultiGetSetBlock_256_Shard-12          21827272               554.8 ns/op            64 B/op          2 allocs/op
BenchmarkKeys-12                                   12793            913201 ns/op          329755 B/op         70 allocs/op
PASS
ok      github.com/orcaman/concurrent-map/v2    532.335s

Test result

> go clean -testcache
> go test ./...
ok      github.com/orcaman/concurrent-map/v2    0.261s

SeunghoonBaek avatar May 04 '23 08:05 SeunghoonBaek

Agreed. This is a good feature to have and I'm currently waiting for this to be released too. Hope maintainers have no issues with this.

pavan-aeturi avatar Aug 06 '24 04:08 pavan-aeturi

cc: @orcaman for rescue

pavan-aeturi avatar Aug 06 '24 06:08 pavan-aeturi