Closed RutledgePaulV closed 9 months ago
Proposed fix: https://github.com/tonsky/datascript/pull/457
Same test from initial report after the change:
(def db
(-> (d/empty-db)
(d/db-with (for [x (range 50000)
:let [temp (str (random-uuid))]
fact [[:db/add temp :item/id x]
[:db/add temp :item/status (rand-nth ["started" "pending" "stopped"])]]]
fact))))
(time
(def results
(d/q '[:find ?e
:where
[?e :item/status ?status]
[(ground "pending") ?status]]
db)))
; "Elapsed time: 11.420875 msecs"
(time
(def results
(d/q '[:find ?e
:in $ %
:where
[?e :item/status ?status]
(pending? ?status)]
db
'[[(pending? ?status)
[(ground "pending") ?status]]])))
; "Elapsed time: 16.736916 msecs"
Closed in #457
I was attempting to clean up a few queries by factoring out some simple rules from my
:where
clauses. However, I immediately began noticing a big decrease in query performance and increased memory usage. I was able to simplify it down to a pretty simple example.I reproduced the issue on both 1.4.2 and 1.5.4 so I don't think it's a recent regression.