LeanTween Performance Boost!Oct 11
First off I have to congratulate DOTween for making some impressive performance increases since it’s last incarnation HOTween. It was legitimately faster than LeanTween in many of the tests. Even if it was only by a hair thin margin, I can verify it was indeed causing less overhead. To keep it in perspective DOTween/LeanTween are still in another ballpark in regards to performance compared to iTween (strangely iTween’s performance was actually decent on more modern mobile).
Even though the margins were tiny, this caused me to totally re-examine my library and examine in what ways I could make it more lightweight. After much scrutinizing, I am proud to say I have been able to best DOTWeen by pretty decent margins! Note: These margins would only reveal themselves if you are animating a crazy amount of objects, so best to use whatever library you prefer based on features/style!
How did I manage to squeeze out that extra CPU juice?
Big switch statements are bad!
– This was becoming overly complex and the performance I was saving by doing operations in-line were overshadowed by the size/complexity of the inline code.
Optimize for Vector3 easing methods.
– There are some values in the ease methods you can calculate once ahead of time like the difference between destination and origin. Cut down on calculations that only needed to be done once instead of 3x for a Vector3 value.
Specific behavior is segmented off
– All the behavior specific to a certain tween is defined by it’s update, initialization and easing method which I swap out when the tween is first called.
– This keeps the kernel or main tween update loop is very small! It’s only around 50 lines of code. This will allow me to keep it very stable, because with less code it is easier to ensure proper behavior.
Saner Easier to Read Library
What I am more satisfied with besides the performance increase is how much more legible the code is compared to before. That huge if/else/switch statement was getting gross! Now I am eager to add more features, as the code just feels neat and tidy and a place I don’t mind hanging out in during my weekends when I get time to devote to the library.
The next update 2.40 is currently on Github. It is looking very stable, and I am readying it for a release to the Asset Store.
iTween not always sluggish performance?
Wait, iTween is actually not terrible in some situations??? This caught me by surprise, it seems the ILCPP outputted version of iTween is actually performing decently! It was only slightly behind DOTween on my iPhone 6 (On older hardware it still performs poorly). Like on other platforms I didn’t expect it to even come close. If anyone can help explain this discrepancy I would be curious to understand!
Some further reading about optimizing C#