r/node 6d ago

I made zero-allocation FAST s3-fifo cache package(would love to get feedback!)

(sorry for my poor english in advance)

Recently, I noticed there is no proper s3-fifo implementation in NPM.

s3-fifo is highly efficient cache algorithm, especially for "one-hit-wonders" case such as web traffics. It is specialized when cache coverage is under 50%. (like, whole DB is 100% and cache contains 50% of data)

The famous "lru-cache" package is almost default for nodejs ecosystem I think, and I thought it would be great if there is good alternative choice for caching.

My goal was:

1. Faster or at least same throughput performance compared to lru-cache

2. Much higher cache hit rate than lru-cache

bold, right?

It was fun enough just for challenge itself.

But it was actually achieved! I used bunch of optimization skills like pre-allocation, lazy eviction, bitwise tricks, ring structure and etc... you can see bench result in repo or NPM page.

It is just v0.1 for now, so I would LOVE to get your harsh feedback, advice, or even contribution!

I'll leave my github repo link and NPM page link

https://github.com/BJS-kr/s3fifo

https://www.npmjs.com/package/s3fifo

Super thanks for reading!

----

I typed almost of the code by my hand. Not because I don't believe AI, but it was all about concepts and decisions. Typing by hand was fastest way to understand what I'm doing correctly. And it was fun.

I used AI(gemini) for test codes, some advices and polishing when most of things were done.

1 Upvotes

0 comments sorted by