Running Version 2.32.
The LTSpline constructor causes huge frameskips. I was losing 6 frames for a 6 point spline.
Here's my code:
Profiler.BeginSample("Spline start");
LeanTween.moveSpline(gameObject, splinePoints, 0.6f)
.setOrientToPath2d(true);
Profiler.EndSample();
splinePoints is a randomly generated array that contains values like:
[(0.0, 5.0, 0.0), (0.0, 5.0, 0.0), (-0.3, 4.8, 0.0), (-0.9, 7.4, 45.0), (-2.3, 9.5, 90.0), (-2.3, 9.5, 90.0)]
[(0.0, 5.0, 0.0), (0.0, 5.0, 0.0), (-0.4, 4.8, 0.0), (-1.6, 7.0, 45.0), (-2.3, 9.5, 90.0), (-2.3, 9.5, 90.0)]
I profiled the code. Here's the breakdown:
Leantween takes 1119.44 ms to spin up a spline from a coroutine.
Of that time. 85.6% is spent in a function called LTSpline.interp(), which for my points was called ~140,000 times. Most of the time is spent in simple math functions for interp, but I'm concerned that it's being called that many times.
The problem is with how you calculate precision when minSegment is between 0.0 and 1.0. Let's say minSegment was 0.01, and totalDistance was 2.0.
float minPrecision = minSegment / SUBLINE_COUNT = .01/50 = .002;
int precision = (int)Ceil(totalDistance / minPrecision) * DISTANCE_COUNT
= Ceil( 2 / .002) * 50 = 1000 * 50 = 50,000
In other words, the smaller a distance the object has to travel once you have segments between [0.0 and 1.0], the more precise LT thinks it needs to be. That doesn't make sense to me, because at those distances, you wouldn't even notice the precision.
I'd recommend adding in a MAX_PRECISION as a quick patch, but you probably want to change the calculation so that it decreases when going from 1.0 --> 0.0.