for example,
let q = new Quaternion
q has many prototype method like q.normalize(), q.multiply() …
Will it be better to make them static:
Quaternion.normalize(q), Quaternion.multiply(p,q) ?
①It seems to save memory, because the instance q no longer has these properties and become smaller?
②If I’m iterating many objects, making them more compact can avoid cache miss?
Hello!
I tried benchmarking a simple case to see if there was any noticeable difference: JSBench.me - JavaScript performance benchmarking playground. At least here the static method seems to be slightly faster, but not by much. So it wouldn’t be worth switching all methods for that. @sebavan what do you think?
I always wanted to implement a Vector3Fast class which would just be an extended (native) Array; with some conversion methods back to Vector3 and so on. Because often all you do with Vectors is pass them around and read/write them. So eventually and ideally you only pass simple arrays around instead of the big Vector3 instances.
But anyway, when I started looking over my code and noticed the bagillion uses of Vector3 I scrapped the idea. What might be useful would be a vector pool for all the temp vectors I use.
what are “big Vector3 instances” what kind of optimization are you expecting to get from this change ( pretend you actually did do it ) what did you score? did you save memory? did you get better frame rates?
Do you mean Vector3Fast is a Float32Array(3) ?
I thought about “Vector3Array” , which is acturally a Float32Array(3*n) .