golang-lru icon indicating copy to clipboard operation
golang-lru copied to clipboard

Add support for golang 1.18 generics

Open druvv opened this issue 2 years ago • 3 comments

Are we planning to add support for 1.18 generics? Would a PR adding generics be accepted?

druvv avatar Mar 22 '22 22:03 druvv

that's a great idea, I am happy to contribute too!

yangcheng avatar Mar 25 '22 10:03 yangcheng

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 ints 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.

bpowers avatar Apr 03 '22 04:04 bpowers

Maybe you can try this: https://github.com/hyahm/gocache

hyahm avatar Apr 29 '22 06:04 hyahm

v2 supports generics.

jefferai avatar Nov 29 '22 14:11 jefferai