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.

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 Spline Controllers, Input Spline Path and Input Spline Shape 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:

  • Max Points Per Unit: This defines the number of sample points per world distance unit.
  • 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 Max Points Per Unit sample points per unit. For example, if you set Cache Density to 100 and Max Points Per Unit to 8, a spline segment with a length of 20 units will calculate 160 cache points.
Use Multi-threading

Split splines

When a spline is used as an input a for Curvy Generator, the CG will update every time that spline is modified. That means that if a spline used for mesh extrusion is a kilometer long, the whole mesh will be extruded even if only the last meter of the spline is modified. A way to avoid this scenario would be to have a CG extruding the static part of the spline, and another one extruding the part that will be updated (that last meter)

Generate only needed data

Mesh generated by CG can have data that you don't need, like collider, tangents, UV2. Disable its generation to reduce generation's time

Experiment

Enable debugging and watch the time a module needs to calculate. Optimize settings and try to design your graph in a clever way

Types

Splines have different Interpolation types, and Orientation types, some being more expensive than others. Use the simplest one that fits your needs.

Check Transform

When a Control Point's transform is modified, the spline is updated accordingly. Part of the CPU time used by a spline goes in checking if one of its CPs' transform was modified. If you know for sure that such modification will not happen, you can disable that behaviour by setting Check Transform to false

Displaying a spline's gizmo takes CPU time, especially if you show cache points' data when you have a lot of them. Consider disabling uneccesarly displayed gizmo data. You can control also define for each spline if it should show its gizmo or not.

We also publish Frame Rate Booster, a Unity asset that automatically reduces your CPU usage. Give it a try, it's easy to use.