golang-lru
golang-lru copied to clipboard
Add support for golang 1.18 generics
Are we planning to add support for 1.18 generics? Would a PR adding generics be accepted?
that's a great idea, I am happy to contribute too!
I converted a fork of this repo I'm playing with to generics in https://github.com/bpowers/approx-lru/commit/3b54b7d007da30e44266dec4fcad189615732027 -- it resulted in a 25% performance improvement because the benchmarks no longer had to allocate when passing int
s to interface{}
parameters (cc @armon):
$ benchstat old.txt new.txt
name old time/op new time/op delta
LRU_Rand-8 226ns ± 2% 167ns ± 1% -26.18% (p=0.008 n=5+5)
LRU_Freq-8 214ns ± 0% 164ns ± 0% -23.57% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
LRU_Rand-8 23.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
LRU_Freq-8 23.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
LRU_Rand-8 2.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
LRU_Freq-8 2.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
container libraries like this are the perfect candidate for generics.
Maybe you can try this: https://github.com/hyahm/gocache
v2 supports generics.