kwrooijen / gungnir

A fully featured, data-driven database library for Clojure.
https://kwrooijen.github.io/gungnir/
MIT License
165 stars 9 forks source link

Change atoms to vars in gungnir.model #24

Closed kwrooijen closed 1 year ago

kwrooijen commented 4 years ago

Currently the model namespace keeps track of registered models and creates maps for "quick" mapping (e.g. mapping a model field to table column). This is mainly for performance benefits.

https://github.com/kwrooijen/gungnir/blob/54fa3b8083c21d52e3c2990ef04cf4a63a1ad8b9/src/cljc/gungnir/model.cljc#L12-L17

These maps are stored in atoms. However it might be nice to actually store then in ^:dynamic defs and change them with alter-var!. This would remove the deref overhead and possibly improve performance slightly. I don't think there's much risk in changing these to defs since they are only set during model registration. Which generally only happens once at system startup.

Ramblurr commented 4 years ago

I don't think there's much risk in changing these to defs since they are only set during model registration. Which generally only happens once at system startup.

I think it is part of normal workflow to re- mode/register! in the repl when working out the kinks in a model. Will that still be supported?

kwrooijen commented 4 years ago

I don't see why not. The point of atoms is to handle parallelism and make sure data stays in sync. I can't imagine having two threads calling model/register! at the same time. Other than that the current behavior will not change.