lovr icon indicating copy to clipboard operation
lovr copied to clipboard

Maybe Use Doubles for Vectors and Physics

Open bjornbytes opened this issue 5 years ago • 3 comments

I wonder if lovr.physics and lovr.math should use doubles instead of floats. There are lots of things to consider here.

  • Lua uses doubles, so using floats internally means converting back and forth between the two types.
  • However, graphics generally uses floats so switching to doubles may mean conversions there.
  • Doubles have better precision which can be pretty meaningful for physics simulation.
  • Doubles take up more memory which can reduce performance when memory/cache effects dominate.
  • Double operations can be faster on 64 bit desktop systems but slower on lower-end hardware (e.g. Quest/Wasm).

To continue, I'd like to run some experiments to see what kind of performance implications doubles would have on different types of hardware. Eliminating conversions and improving precision is pretty favorable, as long as there isn't a significant performance hit.

bjornbytes avatar Dec 11 '20 04:12 bjornbytes

Tried the wrecking ball demo with floats vs doubles on slow 64 bit laptop, performance was comparable, doubles were 3-4% faster.

bjornbytes avatar Feb 10 '21 16:02 bjornbytes

ODE defaults to doubles on 64 bit systems

bjornbytes avatar Mar 27 '22 21:03 bjornbytes

very much worth testing this on arm

shakesoda avatar Mar 27 '22 22:03 shakesoda

Since numbers are doubles and vectors are floats, there will always be conversions in some cases.

It's still possible to recompile ODE to use doubles, and this will improve internal simulation precision even if the physics API uses floats.

Converting physics API to use doubles might be nice, but none of the maf stuff works with doubles.

bjornbytes avatar Apr 15 '23 04:04 bjornbytes