Looking for some advice for working with Datascript in a re-frame application. First: I’ve taken a look at re-posh and like what it’s doing, but got to wondering if there was something out there that just handles creating the ratom wrapper around the datascript connection and is a little less opinionated? I’d like to use the datascript API directly which is one reason why I’m leaning away from re-posh. Second: Any performance considerations, benchmarks, or advice for medium to large size applications? We do have users running our app on older windows devices so I want to be considerate of that.
here's one more alternative for you that works very similarly: https://github.com/jjtolton/rocinante/blob/master/src/clj/new/rocinante/src/cljs/base/lib/data/ds.cljs
Thanks for these!
We use Datascript and posh in our application. It works well. I don't particularly like posh -- it's quite bloated -- but it gets the job done. You can exactly as you say and create a Datascript connection and add a listener to it. That listener will be called anytime a transactionn occurs. You'd then need to update all your ratoms. There is a performance consideration there. That is what posh helps with -- it figures out exactly which ratoms change and only updates those. Figuring out the ones that change is not trivial. Posh's approach is also not perfect.
Yeah saw that it manages an ratom map. Overall - that was my take away. On the datascript side, have you seen any performance issues. I’ve seen in some of the GH issues with users saying that it can be up to 10x slower then a direct lookup? This also seems to be with more involved queries?
No. Our application certainly does not pull in entities at that scale though. You're trading off performance for query flexibility. We chose DS as the store because it is far easier to interact with than updating nested maps. We also use Datomic on the backend so having a similar DSL for transactions is nice.
Thanks for the feedback!
We use datascript for our application, but not reframe. Our datascript dbs are usually quite large (often more than 10,000 entities) We used to use posh, but ran into some performance problems with it and wanted to use the whole datascript api, so we built our own reactive wrapper around datascript similar to https://github.com/hiposfer/rata/blob/master/src/hiposfer/rata/core.cljs (happy to post the code if you want a look). We found for our use case it's faster to rerun all registered lookups than use posh. We also found queries and pulls to be significantly slower than entity lookups, so we only use queries/pulls when they are absolutely necessary (the datoms api is also very fast).