Can anyone explain why long math is extremely slow...
# javascript
l
Can anyone explain why long math is extremely slow compared in JS compared to same code but replacing all Long/LongArrays with Double/DoubleArrays?
e
JS does not have 64-bit integers, so Kotlin/JS has to emulate them
👍 1
l
@ephemient I see. So is using Doubles the only easy semi-workaround? Would using BigInt on the js target perform better that kotlin Long?
e
BigInt aren't easily accessible from Kotlin/JS because they're a newer language feature while Kotlin still targets ES5 (e.g. https://youtrack.jetbrains.com/issue/KT-48980/KJS-Use-of-BigInt-leads-to-JsParserException-what-makes-it-unusable)
and if you're only working with
Long
-sized emulation, BigInt is likely to be slower because of the overhead of handling arbitrary sizes
all the other primitive numeric types, including Double, map to JS
Number
so that's as "native" as it gets
👍 1
l
That makes sense. Thanks for the info.
Now if js would just die… and web would use a language that isn’t terrible, my life would be a lot easier lol…
😁 1
c
While we're on this subject, do you know where
intArrayOf
etc are declared in JS?
e
Array
constructors are hard-wired in the compiler on all platforms