Skip to content

Commit

Permalink
perf: cache d/entity result for immutable entities (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci committed Dec 27, 2024
1 parent d36f1c3 commit 8e07bea
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/frontend/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@
(js/setTimeout #(sync/<sync-start) 1000))))

(comment
(def d-entity-count (volatile! 0))
(def ident->count (volatile! {}))
(def time-sum (volatile! 0))
(defn- setup-entity-profile!
[]
(let [origin-d-entity d/entity
d-entity-count (volatile! 0)
ident->count (volatile! {})]
(let [origin-d-entity d/entity]
(set! d/entity (fn [& args]
(let [r (apply origin-d-entity args)
(let [{r :result time :time} (util/with-time (apply origin-d-entity args))
k (last args)]
(when (= :logseq.class/Query k)
(js/console.trace))
(vswap! d-entity-count inc)
(vswap! ident->count update k inc)
(prn @d-entity-count (:db/id r) k (get @ident->count k))
(vswap! time-sum #(+ time %))
(println @d-entity-count (:db/id r) k (get @ident->count k) @time-sum "ms")
r))))))

(defn ^:export init []
Expand Down

0 comments on commit 8e07bea

Please sign in to comment.