Skip to content

Use Map rather than object-as-Map in our Redux state #3950

@gnprice

Description

@gnprice

This is an optimization, and a code cleanup, that will also help us toward #3949.

Our Redux state tree is currently made up entirely of primitive values, plain arrays, and plain objects. These are very nice for struct-like data structures like User or Message. They're not so nice for key-value maps: we end up using objects as maps, and that's messier in the code and for type-checking than a proper Map. It also turns out to be about 2x slower for building them up and making new ones, as measured in #3339 (comment) .

So, where we use an object as a map, we should use a real Map instead. (Better, perhaps, an Immutable.Map -- that's #3949. But this will be a step on the way.)

We've already converted lots of objects-as-maps to real Maps in much of our code, notably in the return values of caching selectors. The reason we haven't yet done so at all in our Redux state tree is a technical obstacle that shouldn't fundamentally be complicated once we work out how, but will require some working out: we'll need to serialize and deserialize these data structures for redux-persist.

Specifically we'll need to study the docs of redux-persist and friends, then possibly their implementations where docs are inadequate, in order to see how to wire up appropriate serialization and deserialization functions.

Relatedly, we'll want to think through and test the migration path: what happens when a version of the app using a new data structure (for a given spot in the Redux state tree) first launches and there's existing data serialized by a version of the app that used the old data structure.

Some quick notes (adapted from notes I made after some reading in 2019-04) on possible tools for the persistence side:

The migration will happen one data structure at a time; each one is pretty much independent of others. Most of the work will probably come as part of doing the first one, though -- figuring out just how to handle persistence and any migration, and getting that set up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions