-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
32 and 64 bit type casting and performance implications #210
Comments
I believe that the Dart VM can avoid unnecessary double-to-float conversions. Maybe @mraleph can confirm? |
We don't have such an optimisation, though we did consider adding it long ago (but never go to it). It is relatively straightforward to add though (Flutter does not use 32-bit backed vector math, but maybe they should be?). The only problem here is that this optimisation applies only to the pattern |
…uite. Replaced vector_math with vector_math_64. google/vector_math.dart#210
First of all, thank you to everyone who has contributed to this excellent library! 🙌 My brother @IkeBart and I created the bezier.dart package, based on Pomax's Bezier.js. You can see our example page here; perhaps you'll spot some similarities. 😅 Anyway, bezier.dart relies heavily on vector_math, and we're big fans of its design. So... thanks for the cool code! 🥂
For the past few... years, my brother and I have been working on our own game engine, running primarily in the Dart VM but bound to C++ for the low-level stuff like rendering. 👾 For the most part this architecture has worked great, but we've hit a fair number of bottlenecks associated with vectors, and I'm wondering if anyone out there has suggestions or strategies for dealing with them. 🚫 🐢
Since we're using vector_math (not vector_math_64), My guess is that these slowdowns stem from casting back and forth between Dart's 64-bit
double
type and the 32-bit typed data lists that vector_math uses. I'd imagine that each time you perform any operation on a component of a vector, the VM has to cast that component to 64-bit to do the operation... and that anydouble
that gets assigned to a component of a vector must be cast back to 32-bit. 🎣 If that's true, even trivial operations could get pretty expensive. 💸The obvious solution would seem to be "just switch to vector_math_64," right? Well... I'd like to, but as far as I can tell the graphics/shader libraries (and hardware) we're interfacing with only accept 32-bit floating point numbers. 😕
So far we've been dealing with it by porting any heavy vector calculations into C++, and I suppose we can continue to do that. But I figured I should check to see if anyone has encountered similar issues. Surely this kind of bottleneck also pops up when dealing with stuff like WebGL? Or maybe in Flutter? 🦋 Is my understanding of the underlying problem correct? Are there any techniques to mitigate it I might not have considered? A huge thanks to anyone who takes the time to read this or share their experience. ⏳ 🙇
The text was updated successfully, but these errors were encountered: