Fork me on GitHub
#datascript
<
2018-05-23
>
thedavidmeister02:05:26

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

Niki08:05:25

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

ronb14:05:29

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

ronb14:05:27

@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

ronb14:05:42

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

Niki15:05:36

how do you measure memory consumption @ronb?

Niki15:05:09

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

Niki15:05:20

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

ronb15:05:49

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

Niki15:05:21

> 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.

ronb15:05:23

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

ronb15:05:19

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

Niki15:05:41

it seems like v8 and webkit use different approaches

Niki15:05:52

(nan-boxing vs tagging)

Niki15:05:44

> 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.

Niki15:05:06

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

ronb15:05:28

Haha yeah there is soo much magic going on 😄