Here’s some centralized performance feedback for anyone who is interested:
Some of the results surprise me; I expected more overhead with locals and allocs, and less for static vectors operations (creating temps I suppose)
In short though, Vector operations are expensive, which cripples simple operations like synching sprites to physical objects, etc.
using UnityEngine;
public class Routine {
Vector3 target;
Vector3 _a = new Vector3 (1,1,1);
Vector3 _b = new Vector3 (1,1,1);
Vector3 _c = new Vector3 (1,1,1);
Vector3 _d = new Vector3 (1,1,1);
Vector3 _e = new Vector3 (1,1,1);
Vector3 _f = new Vector3 (1,1,1);
Vector3 _g = new Vector3 (1,1,1);
Vector3 _h = new Vector3 (1,1,1);
Vector3 _i = new Vector3 (1,1,1);
public void update () {
// 40fps @ 1000 calls / Update on device (no leak; new struct is still value-type)
// target = new Vector3 (0, 5.0f, 0);
// 20fps @ 1000 calls / Update on device
// target = Vector3.right * 5.0f;
// 30fps @ 1000 calls / Update on device
// Vector3 source = (Vector3)Random.insideUnitCircle;
// target = source;
// 60fps @ 1000 calls / Update on device
// target = _a;
// 30fps @ 1000 calls / Update on device
// target = _a + _b;
// 20fps @ 1000 calls / Update on device
// target = new Vector3 (_a.x + _b.x, _a.y + _b.y);
// 15fps @ 1000 calls / Update on device
// target = _a + _b + _c;
// 7.5fps @ 1000 calls / Update on device
// target = _a + _b + _c + _d + _e + _f;
// 5fps @ 1000 calls / Update on device
// target = _a + _b + _c + _d + _e + _f + _g + _h + _i;
// 3fps @ 1000 calls / Update on device
/* Vector3 a = new Vector3 (1,1,1);
Vector3 b = new Vector3 (1,1,1);
Vector3 c = new Vector3 (1,1,1);
Vector3 d = new Vector3 (1,1,1);
Vector3 e = new Vector3 (1,1,1);
Vector3 f = new Vector3 (1,1,1);
Vector3 g = new Vector3 (1,1,1);
Vector3 h = new Vector3 (1,1,1);
Vector3 i = new Vector3 (1,1,1);
target = a + b + c + d + e + f + g + h + i;
*/
// 3fps @ 1000 calls / Update on device
/* target =
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1) +
new Vector3 (1,1,1);
*/
// 3fps @ 1000 calls / Update on device
/* target =
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one +
Vector3.one;
*/
}
}