We used to cringe a little about a "bit"
- Posted by boost Aug 30, 2017
- 1535 views
I remember (vaguely) we used to cringe a little bit because we used bit 31 to flag a sequence, and we thought other languages would look askance at us for having done so.
Now it seems that V8 JavaScript itself does it. In the article How JavaScript works: inside the V8 engine + 5 tips on how to write optimized code, down the bottom in the "5 tips on how to write optimized code" section it says:
Tagged values: V8 represents objects and numbers with 32 bits. It uses a bit to know if it is an object (flag = 1) or an integer (flag = 0) called SMI (SMall Integer) because of its 31 bits. Then, 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. Try to use 31 bit signed numbers whenever possible to avoid the expensive boxing operation into a JS object.