phuslu / lru

High performance LRU cache
MIT License
182 stars 6 forks source link

can u do a version which i think can be faster if you disregard the time expiry? meaning no time expiry #6

Closed ouvaa closed 3 months ago

ouvaa commented 3 months ago

can u do a version which i think can be faster if you disregard the time expiry? meaning no time expiry

this is for maximum lru speed. i dont need the expiry field.

phuslu commented 3 months ago

I'm not sure how much of a speedup this will bring, but let me implement it in another branch and test it out.

ouvaa commented 3 months ago

@phuslu i'm sure you can come up with better. thx in advance. i'm sure it's faster coz byte overhead will be smaller too

phuslu commented 3 months ago

the nottl LRU version is available here

go get -v github.com/phuslu/lru@$(git ls-remote https://github.com/phuslu/lru nottl | cut -b-40)

And the benchmark result is here https://github.com/phuslu/lru/actions/runs/8308974059/job/22739812511

Considering the improvement is not too big (+13% throughputs, -20% memory usage), I'd like to keep this implementation just in the "nottl" branch.

Make sense?

ouvaa commented 3 months ago

are you joking?! the performance is fantastic. -20% mem usage! 13% throughputs! i wonder why cant you just implement as both like NewWithTTL and New (the default without ttl version)

you can do this. where can i buy you coffee?

dont worry about breaking changes, if you are worried, maybe you shld do v2 or v2.0 tag then.

p.s. : i wrote my own lru in cgo for 3 mths. (it's better than yours but with 150ns cgo latency coz of the ffi but within c it's the fastest) and now u made it obsolete. cant thank you enough for this.

ouvaa commented 3 months ago

@phuslu one last thing, can you do []byte for entries keys and values instead of just string? []byte should be comparable too, not just strings. pls make this "native" and it'll be perfect.

phuslu commented 3 months ago

You convinced me. I just renamed the New function of the master branch to NewTTLCache. Then, I will introduce the code of the nottl branch.

phuslu commented 3 months ago

the first mixed version(LRUCache & TTLCache) is available in latest master branch.

later I will do some tweaks for options and test coverage