4 ms·
> But there is only one type of number in javascript. Everything is just a double(BigInt aside). There is nothing stopping JS engines from trying to infer when
by vanderZwan 6y ago
> But there is only one type of number in javascript. Everything is just a double(BigInt aside).
There is nothing stopping JS engines from trying to infer when a number is only an integer and optimize for that. In fact, that's what Small Integer (SMI) optimizations are all about[0].
It's just that |0 isn't really able to guarantee that our number value is the type of SMI that V8 optimizes for (since the V8 SMIs are 31 bits, and bitmasking operations only guarantee 32 bit integers)
https://ponyfoo.com/articles/an-introduction-to-speculative-optimization-in-v8 https://ponyfoo.com/articles/an-introduction-to-speculative-...