jaredwray / keyv

Simple key-value storage with support for multiple backends
https://keyv.org
MIT License
2.61k stars 143 forks source link

Keyv serializing values irrespective of storage medium. #1162

Closed mmillies closed 2 weeks ago

mmillies commented 2 weeks ago

I guess this is probably more an investigative question.

Is your feature request related to a problem? Please describe.

I was analyzing performance metrics in an application that uses this library and noticed the serialization/deserialization routines were getting executed for an in-memory store without compression.

I was surprised. Is there a reason the value must be serialized when storing in memory, specifically when compression is NOT configured?

https://github.com/jaredwray/keyv/blob/main/packages/keyv/src/index.ts#L317

Describe the solution you'd like

I see areas where there is an if-statement checking if compression is turned on before doing the deserialization routines (which is what I was expecting).

https://github.com/jaredwray/keyv/blob/main/packages/keyv/src/index.ts#L220

Am I missing something in the framework that causes serialization of the values to be a requirement when compression is NOT enabled?

To be clear, I'm currently testing "turning off" serialization by overriding the serialization/deserialization functions with no-op functions. (thank y'all for putting those configuration overrides in to make this easy to do) So I'm not actively worried about this. I am just curious if I am missing something.

I can also throw a PR out there for patching if this is deemed as something that should be patched.

jaredwray commented 2 weeks ago

@mmillies - thanks for sending this out and yes we know that this is an issue and we plan to resolve it soon by adding in a better way to handle in-memory solutions. We are currently working on thew new @keyv/redis adapter but in the future will be doing the following:

Hope this helps and appreciate that you already figured out a work around for things like this. Also, if you just want to do in-memory I would highly suggest using CacheableMemory which is the next generation caching library. 🎉

mmillies commented 2 weeks ago

yep, using your CacheableMemory package at the moment 🥳 . We're a recent migration from the old cache-manager (pre-v4) up to ya'lls latest.

I'm just troubleshooting some performance stuff, hoping the serialization tweak gets me past the finish line.

And thanks again for doing all this. Pretty neat stuff for sure. 👍

(And thanks for supporting both module types. made the upgrade easier)