tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.5k stars 309 forks source link

Using keywords for attribute values in vanilla js #105

Closed vvvvalvalval closed 9 years ago

vvvvalvalval commented 9 years ago

I'm using Datascript from Javascript in the browser, and I have not found any way to use keywords for attribute values; I believe it could be valuable for performance reasons.

Is this a design choice? If not, maybe just exposing a keyword function could do the trick.

tonsky commented 9 years ago

Are you talking about clojurescript keywords? They are just wrappers around strings, so don’t expect perf boost there

vvvvalvalval commented 9 years ago

Yes I am.

This thread led me to think keywords would be faster to check for equality - but I believe you, you've probably been further down this road than me.

tonsky commented 9 years ago

Right. CLJS identical check for keywords is reference comparison, whether for JS strings it is not. On the other hand, DS relies on compare, not on equality/identity check. Compare for keywords is slightly more complicated than compare on strings. Overall, you should not lose anything using strings