Jotai v2.20.0 and the Store Building Blocks

A small performance fix with a long history

Hi,

It was more than one year ago when we released Jotai v2.12.0.

It introduced a new idea to expose some internals so that ecosystem libraries can extend Jotai's core capabilities. It was collaborative work with David Maskasky, who is the maintainer of jotai-effect, jotai-scope, and so on.

Why Building Blocks

I didn't like extending the store after creation, because that would cause some mismatches, like having two different capabilities over time. What I chose was to accept customization at the time of building a new store. I call this customization method the building blocks of a store.

The initial implementation was somewhat limited. It didn't provide full customization, and the API was a little bit hard to deal with.

Over time, we've improved it. Around v2.15.0, we mostly finished it, and the API became both flexible and safe, or hard to misuse.

Performance Regression

A long time later, at least for me, someone reported that there seemed to be a performance regression. The major reason was the use of WeakMap, which was meant to improve the flexibility of building blocks.

We iterated on ideas to solve it, and I decided to go with one idea, which is not super clean, but fits with my mental model. Basically, instead of using WeakMap, it now passes everything as parameters.

Toward Jotai v3

Many users don't need to understand the subtlety. But I just wanted to share that there was some history behind it.

Jotai v2.20.0 was released a couple of days ago.

Now, I'm ready to think about Jotai v3.

Happy coding.

Reply

or to participate.