mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 14:43:56 +00:00
perf: faster has-tag?
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
{:source-aliases #{:cljs}
|
||||
:source-paths-ignore-regex ["src/resources" "target.*"]
|
||||
:paths-ignore-regex ["src/resources"]
|
||||
:clean {:ns-inner-blocks-indentation :same-line}}
|
||||
:clean {:ns-inner-blocks-indentation :same-line}
|
||||
:additional-snippets [{:name "profile"
|
||||
:detail "Insert profile-fn"
|
||||
:snippet
|
||||
"
|
||||
(comment
|
||||
(require '[logseq.common.profile :as c.p])
|
||||
(do (vreset! c.p/*key->call-count {})
|
||||
(vreset! c.p/*key->time-sum {}))
|
||||
(c.p/profile-fn! $1) )"}]}
|
||||
|
||||
18
deps/common/src/logseq/common/profile.clj
vendored
Normal file
18
deps/common/src/logseq/common/profile.clj
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
(ns logseq.common.profile
|
||||
"Utils for profiling")
|
||||
|
||||
(defmacro profile-fn!
|
||||
[f & {:keys [print-on-call? gen-k-fn]
|
||||
:or {print-on-call? true}}]
|
||||
`(let [origin-f# ~f
|
||||
gen-k-fn# (or ~gen-k-fn (constantly (keyword ~f)))]
|
||||
(set! ~f (fn [& args#]
|
||||
(let [start# (cljs.core/system-time)
|
||||
r# (apply origin-f# args#)
|
||||
end# (cljs.core/system-time)
|
||||
k# (gen-k-fn# r#)]
|
||||
(vswap! *key->call-count update k# inc)
|
||||
(vswap! *key->time-sum update k# #(+ % (- end# start#)))
|
||||
(when ~print-on-call?
|
||||
(println "call-count:" (get @*key->call-count k#) "time-sum(ms):" (get @*key->time-sum k#)))
|
||||
r#)))))
|
||||
11
deps/common/src/logseq/common/profile.cljs
vendored
Normal file
11
deps/common/src/logseq/common/profile.cljs
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
(ns logseq.common.profile
|
||||
"Utils for profiling"
|
||||
(:require-macros [logseq.common.profile]))
|
||||
|
||||
(def *key->call-count
|
||||
"key -> count"
|
||||
(volatile! {}))
|
||||
|
||||
(def *key->time-sum
|
||||
"docstring"
|
||||
(volatile! {}))
|
||||
24
deps/db/src/logseq/db/frontend/entity_util.cljs
vendored
24
deps/db/src/logseq/db/frontend/entity_util.cljs
vendored
@@ -7,10 +7,18 @@
|
||||
|
||||
(defn- has-tag?
|
||||
[entity tag-ident]
|
||||
(let [tags (:block/tags entity)]
|
||||
(some (fn [t] (or (= (:db/ident t) tag-ident)
|
||||
(= t tag-ident)))
|
||||
(if (coll? tags) tags [tags]))))
|
||||
(some (fn [t]
|
||||
(let [db-ident (:db/ident t)]
|
||||
(if (keyword? db-ident)
|
||||
(identical? (.-fqn db-ident) (.-fqn ^keyword tag-ident))
|
||||
(keyword-identical? t tag-ident))))
|
||||
(:block/tags entity)))
|
||||
|
||||
(comment
|
||||
(require '[logseq.common.profile :as c.p])
|
||||
(do (vreset! c.p/*key->call-count {})
|
||||
(vreset! c.p/*key->time-sum {}))
|
||||
(c.p/profile-fn! has-tag? :print-on-call? false))
|
||||
|
||||
(defn internal-page?
|
||||
[entity]
|
||||
@@ -18,8 +26,8 @@
|
||||
|
||||
(defn class?
|
||||
[entity]
|
||||
(or (= (:db/ident entity) :logseq.class/Tag)
|
||||
(has-tag? entity :logseq.class/Tag)))
|
||||
(or (has-tag? entity :logseq.class/Tag)
|
||||
(keyword-identical? (:db/ident entity) :logseq.class/Tag)))
|
||||
|
||||
(defn property?
|
||||
[entity]
|
||||
@@ -32,7 +40,7 @@
|
||||
;; db based graph
|
||||
(has-tag? entity :logseq.class/Whiteboard)
|
||||
;; file based graph
|
||||
(= "whiteboard" (:block/type entity))))
|
||||
(identical? "whiteboard" (:block/type entity))))
|
||||
|
||||
(defn closed-value?
|
||||
[entity]
|
||||
@@ -45,7 +53,7 @@
|
||||
;; db based graph
|
||||
(has-tag? entity :logseq.class/Journal)
|
||||
;; file based graph
|
||||
(= "journal" (:block/type entity))))
|
||||
(identical? "journal" (:block/type entity))))
|
||||
|
||||
(defn page?
|
||||
[entity]
|
||||
|
||||
Reference in New Issue
Block a user