I noticed that the persist config expects the storage object to be async, so setItem, getItem and removeItem always returns a promise, and if no async/await syntax is used, a new instantly resolved Promise instance gets created. This introduces a bit of an overhead if you call this a lot of times, as this can't get fully optimized away.
Instead, those functions could return Promise<T> | T, so that depending on if the result is awaitable it will be awaited and if not it is used synchronously.
Hi!
I noticed that the persist config expects the storage object to be async, so
setItem
,getItem
andremoveItem
always returns a promise, and if noasync/await
syntax is used, a new instantly resolved Promise instance gets created. This introduces a bit of an overhead if you call this a lot of times, as this can't get fully optimized away.Instead, those functions could return
Promise<T> | T
, so that depending on if the result is awaitable it will be awaited and if not it is used synchronously.This means, your local storage code and my react-native-mmkv storage "plugin" code gets faster.
Unrelated; why is everything a string? When I want to persist only a boolean, why is it persisted using a string? Will everything be JSON-serialized?