4 ms·
Improving DataView performance in V8
- saagarjha 8y agoIt seems from the code snippets that DataViews are strongly typed. So what happens when you load data with the wrong type? Does JavaScript have "undefined behavior"?
- aappleby 8y agoIt's just a blob of bytes. If you write a 32-bit float and then read an int from the same location, you get whatever int those 32 bits form.
- Waterluvian 8y agoThat generally tells me that this tool is meant for developers smarter than me to make the appropriate abstractions for me to use. Not for me to consider this a core part of my web app development toolkit. :)
- Ajedi32 8y agoVery much in keeping with the [Extensible Web Manifesto][1]. [1]: https://extensiblewebmanifesto.org/ https://extensiblewebmanifesto.org/
- travisoneill1 8y ago> this tool is meant for developers smarter than me Developers solving different problems than you. When you run into a problem that needs this tool don't hesitate to use it. Dealing with data structures like this isn't really harder than the usual JS stuff, just different and a learning curve.
- gsnedders 8y agoAnd to be clear, unlike in C it's well-defined what those 32-bits are, because it's defined to be an IEEE 754 binary float32.
- deleted 8y ago[deleted]
- m1el 8y agoThe data is converted to the target type. If you pass a string to setFloat64, the string will be converted to float64 first.
- aappleby 8y agoI'm one of the Google Maps developers that worked on the typed-array version of the loading code - hooray for DataView finally being a viable alternative. :)
- adzm 8y ago> we also removed support for indices or offsets that are too large (outside of Smi range) inside the TurboFan-optimized code What exactly is Smi range? I have a feeling it is something obvious that I'm overlooking.
- ryanpetrich 8y agoIn V8, small machine integers are signed 31bit integers on 32bit architectures and signed 32bit integers on 64bit architectures.
- kbumsik 8y agoGreat article. I didn't know DataView was much slower than TypedArrays. I always prefer DataView over TypedArrays when writing protocols and file formats, because TypedArrays follows system endianness so you cannot set endianness manually. (It is true that big-endian CPU is very rare but I cannot stop worrying about endianness.)
- tokyodude 8y agoThis is great. Let's hope they plan to also update TypedArray support in general. NativeArrays are still like 2x faster than Float32Arrays for matrix math. Probably has to be that way ATM as the math has to be promoted to double and back? Still, v8 seems to be about 2x slower than SpiderMonkey in this area http://greggman.github.io/webgl-matrix-benchmarks/matrix_benchmark.html http://greggman.github.io/webgl-matrix-benchmarks/matrix_ben...