{{description>Optimize Unity spline performance with Curvy Splines! Modify cache density, use threading, pooling, and CG tweaks for a smoother experience. Learn more here.}} {{indexmenu_n>7}} ====== Performance Tips ====== Curvy Splines tries to cater to the widest audience possible. Doing so, it can make some choices performance wise that are not the optimal for your unique use case. In this page you will learn about those choices and the way you can tweak Curvy Splines to get the most of it. And don't forget, Unity's profiler is your best friend. ===== Caching ===== === The concept === The data of a spline point is defined through mathematical equations. In addition to the possibility of solving those equations each time a point's data is needed, which will take valuable CPU time, Curvy Splines offer an alternative through caching. Caching stores the data of a group of points in memory for further need. That group of points is called cache points. For example, a one meter long spline can be cached as 100 cache points, one every centimeter. If you need the data of a point in between two cache points, a linear interpolation will be done between those two cache points. This mechanism allows gains in performance when getting data from a spline, but it comes with a cost: * Caching uses memory * Constructing the cache takes time * The linear interpolation between cache points returns values that diverge from the actual spline In summary, the more cache points there are, the more the cached data is precise, but the slower it is to build them, and in some case to access them. === How to increase performance === == Activate it when optional == The [[:documentation:controllers:start|Spline Controllers]], [[documentation:generator:modules:inputsplinepath]] and [[documentation:generator:modules:inputsplineshape]] have optional "Use Cache" options. Activate them if you want to make them use the spline's cache. == Use the right API methods == If using the Curvy Splines through the API, some methods have a "Fast" alternative that uses the cache. For example, CurvySpline.InterpolateFast uses cache while CurvySpline.Interpolate doesn't. == Set the correct number of cache points == The cache density set by default to new splines should be good for most users, but if you work with very long or very short splines, you might need to tweak the cache density such as to use the lower satisfying amount of cache points possible. You can define that number thought those two parameters: * [[documentation:splines:curvyspline:#Max Points Per Unit]]: This defines the number of sample points per world distance unit. * [[documentation:splines:curvyspline:#Cache Density]]: This is a value between 1 and 100. The higher the number, the more sample points are per distance unit. When it is equal to 100, the spline will have [[documentation:splines:curvyspline:#Max Points Per Unit]] sample points per unit. For example, if you set Cache Density to 100 and [[documentation:splines:curvyspline:#Max Points Per Unit]] to 8, a spline segment with a length of 20 units will calculate 160 cache points.