Distinguishing types between int
and double
#30543
Labels
Duplicate
An existing issue was already created
int
and double
#30543
Search Terms
int double, integer, float, double
Suggestion
This proposal introduces new number types
int
anddouble
orfloat
. Goal is to make a difference between integers and floating point numbers since some JavaScript engines does such kind of difference in the back-end.Use Cases
As we know about V8 engine, it uses pointer tagging to distinguish between different types such as
Smi
(small integer),HeapObject
,WeakHeapObject
etc.Consider this example:
For both
o1
ando2
object the engine will create same shapes. See image below:However, after changing
o2.x
to some double value, say thato2.x = 5.5;
then V8 will use create new subtree from that shape and the old subtree in this shape will be marked as deprecated and will be garbage-collected. Reason for this is because there is a difference how V8 storesSmi
andDouble
values in the memory.Here is second image after changing
x
to5.5
:Read more here: https://ponyfoo.com/articles/javascript-performance-pitfalls-v8#smi-to-double-migrations
Examples
Some code examples from the proposal:
This proposal does not require a breaking change, since
number
types are also okay, if one considers some possible performance pitfalls.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: