Merge allgress query analysis branch to tonsky.#12
Merge allgress query analysis branch to tonsky.#12allgress wants to merge 1 commit intotonsky:masterfrom allgress:master
Conversation
|
Small tip about whitespace changes, to view diff via github without whitespace changes just add w param with true value to URL, for example: https://github.com/tonsky/datascript/pull/12/files?w=true |
0f63209 to
031e4f7
Compare
|
Thanks for your work on this allgress. I made a few updates there https://github.com/EwenG/datascript/tree/analyze-q. Updates include:
I don't know if this should be merged into datascript. I still think there is something wrong with modifying the listen! API. But I am also concerned with how datascript would scale when a lot of callbacks are registered, especially in the context of a GUI where a lot of events can be generated (think mouse dragging events). I would love to know tonsky opinion on this. |
|
This is excerpt from email discussion with @allgress :
I’m not sure that the whole idea of “reverse” query can be solved, even in datalog. But much simpler approach, like |
|
Isn't it what allgress "index keys" already do? analyze-q is just syntactic sugar to extract those index keys ('[_ :user/name ] or '[room-id :room/messages ']) from a query. This is indeed an approximation since it is "only" a static analysis. |
|
@EwenG sorry, haven’t looked at your code before, without analyse-q your API looks like what I’ve planned, because we don’t promise too much, only subscription to index we can efficiently support. I’ll look closer into your implementation and report back |
|
This sounds a lot like what the RETE algorithm does - it effectively builds a custom network/indexes that exactly fit the set of queries/rules known to the system and shares common sub expressions for efficiency. Trades memory for runtime. |
|
Are you still considering this feature? Looks extremely useful. |
|
@jeluard yes, but haven’t got time to implement it or do a review on PR. At some point, something like this, yes |
|
@allgress are you guys still using this for your own apps? how is it working for you? |
|
@atroche We're using Datascript, but not the allgress branch with query-based notifications. We've moved away from the single state atom approach, and have really embraced the immutable aspect of Datascript. Our web components might receive an instance of a Datascript DB via an attribute from a parent, or create it themselves through a service call. Child components often publish relevant changes through events, from which listeners can update their own instance as appropriate. Since we use freactive, sometimes we'll make a lens which represents a specific query or "view" on the DB. We've found that this approach allows us to keep the Datascript instances fairly small (for our apps, at least), and haven't had any perf issues which would require query-specific notifications. |
|
No, we are using the Clara rules engine which gives you these features (and more) by design. |
|
Hadn't seen this thread before... I'll just chime in to mention that this sounds a lot like parts of https://github.com/mpdairy/posh. In fact, there's an That having been said, I'd like to point out that there's some discussion on #132 in the direction of incremental materialized view maintenance which would go one step further in actually preventing re-computation of queries, instead using previous results and tx-diffs to compute the new query results far more efficiently. |
This branch adds query analysis and the ability to listen only for transactions that would affect a particular query. The query analysis remembers which parts of the index are used in the query, and transacted datoms are analyzed to see if they update any of these. May be a useful performance optimization, rather than notifying all listeners of all transactions and leaving it to the listener to query against tx-data, decide if any changes are relevant, etc.
Not sure if this is the best approach, particularly since the logic is essentially duplicated between the query and analysis functions. Also some annoying whitespace changes I didn't catch before committing, sorry.