In my app I need an optimization booster. I noticed that records are significantly faster than maps (probably because record' fields are accessed with native class field access by the JVM)
The map I'm replacing used namespaced keywords as keys
(def m {:app.core/k 1 })
I'm replacing the definition with
(defrecord R [k])
(def m (->R 1))
Code is
(defn two [m] (assoc m :app.core/k 2))
Unfortunately, running this code when m is a record, it assoc a new namespaced key :app.core/k that won't benefit optimization.
Is it possible to declare the record such that it will use namespaced keyword ?
There is no such a possibility for this, at least as I know. Only non-qualified names for deftype/defrecord declarations are allowed.
I'm not sure if it will help, but still: you may declare instances of typed records using the standard # reader macro prepending any map. So probably you could get rid of the most of constructor functions:
(def m #some.ns.YourRecord {:foo 1 :bar 2 :baz 3})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With