datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2018-05-23T02:48:26.000043Z

@ronb yes, internally there is "high bits" and "low bits", that doesn't change based on value

2018-05-23T08:25:25.000605Z

as far as I remember, at least v8 can detect 31-bit ints and it’s more efficient to store them https://www.html5rocks.com/en/tutorials/speed/v8/#toc-topic-numbers

2018-05-23T14:20:29.000175Z

just compared memory consumption of my double trick to goog.math.Long. Using a double in this way is much smaller on every browser: Firefox 4x, Chrome 5x, Safari 5x

2018-05-23T14:21:27.000403Z

@tonsky @thedavidmeister the 31 bit rule only applies to 32 bit machines. 64bit engines use NAN-boxing. I found a good description here: https://softwareengineering.stackexchange.com/questions/185406/what-is-the-purpose-of-nan-boxing

2018-05-23T14:23:42.000533Z

basically a double is stored in the pointer directly with one of the redundant NaN values active (JS only has a single NaN representation)

2018-05-23T15:14:36.000822Z

how do you measure memory consumption @ronb?

2018-05-23T15:15:09.000076Z

also, using Long means the values will be boxed, no wonder memory consumption jumped up

2018-05-23T15:16:20.000893Z

> V8 doesn't actually use 63-bit smi values on 64-bit machines, AFAIK. so just 31 bits for fast immediate integers :(

2018-05-23T15:19:49.000733Z

@tonsky I used memory snapshots>containment in chrome to check memory consumption

2018-05-23T15:20:21.000264Z

> if a numeric value is bigger than 31 bits, V8 will box the number, turning it into a double and creating a new object to put the number inside.

2018-05-23T15:20:23.000033Z

could’nt figure out how to do this in Safari, so i just used all js memory and compared

2018-05-23T15:21:19.000800Z

hmm strange, that would mean my measurements were incorrect somehow. thanks for the info

2018-05-23T15:21:41.000800Z

it seems like v8 and webkit use different approaches

2018-05-23T15:21:52.000428Z

(nan-boxing vs tagging)

2018-05-23T15:34:44.000601Z

> NaN-boxing has the obvious advantage of not allocating doubles on the heap. This reduces cache pressure, GC pressure, and such. That's why Moz and JSC chose it. V8 on the other hand has not chosen it, at least not yet, anyway.

2018-05-23T15:37:06.000219Z

damn, it’s so tricky to convince JS to exactly what you want

2018-05-23T15:53:28.000616Z

Haha yeah there is soo much magic going on 😄