mirror of
https://github.com/penpot/penpot.git
synced 2026-11-06 18:10:39 +00:00
⚡ Reuse uuid instances when decoding transit on the frontend (#12792)
This commit is contained in:
parent
6a1b58c310
commit
7fa225115e
@ -110,6 +110,37 @@
|
||||
(.set cache value kw)
|
||||
kw))))))
|
||||
|
||||
#?(:cljs
|
||||
(def ^:private uuid-cache-size
|
||||
"Twice the ids of a very large page (~60k shapes), so decoding one
|
||||
page does not rotate the cache."
|
||||
131072))
|
||||
|
||||
#?(:cljs (def ^:private recent-uuids (js/Map.)))
|
||||
#?(:cljs (def ^:private previous-uuids (js/Map.)))
|
||||
|
||||
#?(:cljs
|
||||
(defn clear-uuid-cache
|
||||
"Forget the cached uuids, so the ids of a closed file can be freed."
|
||||
[]
|
||||
(set! recent-uuids (js/Map.))
|
||||
(set! previous-uuids (js/Map.))))
|
||||
|
||||
#?(:cljs
|
||||
(defn- read-uuid
|
||||
"Give the same uuid instance for each value. Entries live in two
|
||||
generations: when the recent one is full it becomes the previous one
|
||||
and the older one is dropped, so the cache stays bounded."
|
||||
[value]
|
||||
(or (.get recent-uuids value)
|
||||
(let [id (or (.get previous-uuids value)
|
||||
(parse-uuid value))]
|
||||
(when (>= (.-size recent-uuids) uuid-cache-size)
|
||||
(set! previous-uuids recent-uuids)
|
||||
(set! recent-uuids (js/Map.)))
|
||||
(.set recent-uuids value id)
|
||||
id))))
|
||||
|
||||
(add-handlers!
|
||||
#?@(:clj
|
||||
[{:id "file"
|
||||
@ -128,7 +159,7 @@
|
||||
|
||||
#?(:cljs
|
||||
{:id "u"
|
||||
:rfn parse-uuid})
|
||||
:rfn read-uuid})
|
||||
|
||||
#?(:cljs
|
||||
{:id ":"
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
[app.common.math :as mth]
|
||||
[app.common.path-names :as cpn]
|
||||
[app.common.render-wasm.wasm :as wasm-state]
|
||||
[app.common.transit :as t]
|
||||
[app.common.types.component :as ctc]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.shape :as cts]
|
||||
@ -631,6 +632,7 @@
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(t/clear-uuid-cache)
|
||||
(let [project-id (:current-project-id state)]
|
||||
(rx/of (dwn/finalize file-id)
|
||||
(dpj/finalize-project project-id)
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.logging :as log]
|
||||
[app.common.time :as ct]
|
||||
[app.common.transit :as t]
|
||||
[app.worker.impl :as impl]
|
||||
[app.worker.selection :as selection]
|
||||
[app.worker.snap :as snap]
|
||||
@ -78,6 +79,7 @@
|
||||
(update :pages-index dissoc page-id)
|
||||
(update ::selection dissoc page-id)
|
||||
(update ::snap dissoc page-id)))
|
||||
(t/clear-uuid-cache)
|
||||
(log/dbg :hint "page index dropped" :id page-id ::log/sync? true)
|
||||
nil)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user