Is it useful to cache add-on settings got by browser.StorageArea.sync.get?

Because I thought it would be a good idea I implemented some caching of the add-on settings in my add-on:

It is only runtime caching, i.e. just to have the options in the JS code saved in an JS object or so.

I wonder if that is really helpful. Assume that I may access the same option two or three times (but often, of course, only one time) when the JS is executed and I may access say 10 of 30 options.

Is it useful in such a case to cache them? Or is it useful in general?
Or to ask it in a different way: Is Firefox really slower when fulfilling the promise got by browser.storage.<storageType>.get() then when I just get the cached option from a JS variable?
Or does Firefox include an internal caching mechanism for these options?

Whether it matters for micro-performance really depends on your access pattern.

I actually hold a complete clone of both sync and local storage in memory, where each individual value is frozen.
The reason is more semantic, though. This way, I can access everything synchronously (in some places it really matters to have a defined order for things) and am sure update events are only fired when values really change.
I don’t think there is a notable memory overhead, because I would have all those values somewhere in memory anyway, the only difference is that there is a “global registry” now (and doing reads on that is definitely faster than through the API). It may actually be less memory intensive because there won’t be any duplicates of the same value.

Here is my implementation:

1 Like

Okay, thanks for the reply. I was more about performance as you noticed, but, yes, of course semantics are also a good reaon to cache those values.