dgraph-io / ristretto

A high performance memory-bound Go cache

Home Page:https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE]: Support for Type Parameters, aka, generics

paivagustavo opened this issue · comments

Have you tried Ristretto before this proposal? and did not find anything similar?

No response

What you wanted to do.

I would like to be able to use the ristretto cache using type parameters to avoid conversions to/from interface{}. This both makes the code more performant and also cleaner to use.

What you actually did.

No response

Why wasn't it great, with examples.

No response

Additional information.

I've done an experiment migrating ristretto to Generics, It does seems to have positive impact on performance as well as we can see on some benchmarks added:

benchstat
name                            old time/op    new time/op    delta
CacheSet-8                        26.8ns ±15%    19.4ns ± 6%   -27.36%  (p=0.000 n=10+10)
ConcurrentCacheSetNeverEvict-8    80.1ns ±10%    78.4ns ±24%      ~     (p=0.661 n=9+10)

name                            old speed      new speed      delta
CacheSet-8                      37.5MB/s ±14%  51.5MB/s ± 6%   +37.18%  (p=0.000 n=10+10)

name                            old alloc/op   new alloc/op   delta
CacheSet-8                          113B ± 5%       79B ± 5%   -30.38%  (p=0.000 n=10+10)
ConcurrentCacheSetNeverEvict-8      105B ± 0%       88B ± 0%   -16.19%  (p=0.001 n=7+7)

name                            old allocs/op  new allocs/op  delta
CacheSet-8                          1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
ConcurrentCacheSetNeverEvict-8      3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)

I'm willing to submit these changes (and some other improvements) if Ristretto is willing to add support to Type Parameters.

Or you can try my high hit ratio & good perofrmance generic cache package:
https://github.com/Yiling-J/theine-go