I’m working on a game using cljs + expo + three.js, and due to performance reasons I’ve decided to use js-objects in situations where the data is “simple”. Essentially I keep the game state in a hash-map
, and then I keep references and settings as js-objects on the “game objects” (THREE/Mesh
es). This is because to my understanding and from my measurement, (.-a #js {:a 10})
is a lot faster than (:a {:a 10})
. Since I’m trying to keep 60fps, even fractions of milliseconds can add up, and these values are accessed often.
However, some functions are now getting pretty stupid. I feel that having to hard code all .-
calls aren’t the right way to go. Here’s an example:
(defn go->zone-go
[go]
(and go
(or
(and (.. go -state)
(.. go -state -cardParent)
(.. go -state -cardParent -state)
(.. go -state -cardParent -state -zoneId)
(.. go -state -cardParent))
(and (.. go -parent)
(.. go -parent -state)
(.. go -parent -state -zoneId)
(.. go -parent))
(and (.. go -state)
(.. go -state -zoneId)
go))))
I felt there ought to be a better way to write this, e.g. a macro, that lets me write this: (js-> go -state -cardParent -state -zoneId)
which would expand to:
(and (.. go -state)
(.. go -state -cardParent)
(.. go -state -cardParent -state)
(.. go -state -cardParent -state -zoneId)
I’ve looked around a bit but haven’t been able to figure out which libraries doesn’t sacrifice performance.
Thankful for any thoughts and tips. I’m still just a beginning cljs writer.