xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
554 stars 25 forks source link

Binary data in models #529

Closed vojto closed 1 year ago

vojto commented 1 year ago

Hey everyone,

I was wondering if there's any way of storing binary data in Mobx Keystone.

We are using YJS, and their format is binary.

We found that adding base64 serialization/deserialization adds a lot of memory overhead when dealing with larger amounts of data.

So for example– we read the documents from database, they come in binary format. Now we have to convert to base64 just so we can store them in Mobx Keystone models. And then back to binary, in order to initialize the YJS documents.

We don't care about JSON compatibility - we have custom binary format for serialization.

Is there any workaround you would suggest we use?

cc @maccman

xaviergonz commented 1 year ago

if you don't want to use json serialization or patches or snapshots you might just create a mobx observable.ref in the class as a class variable. note it will be volatile though and will only live as long as the class itself does

xaviergonz commented 1 year ago

or if you don't even care about observability at all just a plain standard class variable would do

vojto commented 1 year ago

Thanks a lot, this is helpful!