Skip to content

Commit 7b6d6c4

Browse files
committed
perf: add unsafe->Entity, faster 'Pages'
On Chrome, Mac M4Max 40000 pages graph, sorted by updated-at, from 1000+ms -> 200-300ms
1 parent a5ac90a commit 7b6d6c4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

deps/db/src/logseq/db/common/entity_plus.cljc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
(d/entity db eid)))
7575
(d/entity db eid)))
7676

77+
(defn unsafe->Entity
78+
"Faster verison of d/entity without checking e exists.
79+
Only use it in performance-critical areas and where the existence of 'e' is confirmed."
80+
[db e]
81+
{:pre [(pos-int? e)]}
82+
(Entity. db e (volatile! false) (volatile! {})))
83+
7784
(defn db-based-graph?
7885
"Whether the current graph is db-only"
7986
[db]

deps/db/src/logseq/db/common/view.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
(let [refs-count? (and (coll? sorting) (some (fn [m] (= (:id m) :block.temp/refs-count)) sorting))
295295
exclude-ids (when db-based? (get-exclude-page-ids db))]
296296
(keep (fn [d]
297-
(let [e (d/entity db (:e d))]
297+
(let [e (entity-plus/unsafe->Entity db (:e d))]
298298
(when-not (if db-based?
299299
(exclude-ids (:db/id e))
300300
(or (ldb/hidden-or-internal-tag? e)

0 commit comments

Comments
 (0)