This is a heads-up to spread the word about a couple of new APIs that landed 2023.1.0a18 and provide the opportunity to significantly improve the performance of scripts that need to transform large numbers of points/lines or that draw many lines using the existing Gizmos.DrawLine() API. These new APIs deliver better performance by allowing arbitrarily sized batches of points/lines to be transformed or batches of lines to be drawn with a single API call drastically reducing the overhead involved in repeatedly marshalling data between and transitioning from managed user code (C#) to native Unity engine code (C++). The new APIs fall into two categories: Batch Transform APIs There are many situations when working with Unity where you have a requirement to convert points or vectors from one space to another - usually from the local space of a game object to world space or vice versa. The usual way to do this is with the family of TransformXXX and InverseTransformXXX functions found in the Transform class: Transform.TransformPoint() Transform.TransformDirection() Transform.TransformVector() Transform.InverseTransformPoint() Transform.InverseTransformDirection() Transform.InverseTransformVector() Each of these functions takes a single Vector3, transforms it and returns the result which makes them very simple to use but as each API call made incurs an overhead marshalling data and transitioning from managed to native code they are also significantly inefficient when working on larger data sets as they have to be called repeatedly on each point/direction/vector in turn. From 2023.1 this inefficiency is largely eliminated with batch versions of each of these functions that allow you to transform as many points/directions/vectors as necessary with a single API call so the overhead is only incurred once: Transform.TransformPoints() Transform.TransformDirections() Transform.TransformVectors() Transform.InverseTransformPoints() Transform.InverseTransformDirections() Transform.InverseTransformVectors() Each of these can take a single Span<Vector3> containing the source points/directions/vectors each of which will be overwritten with the transformed versions or they can take a ReadOnlySpan<Vector3> for the source data and a separate Span<Vector3> to receive the transformed versions leaving the source data intact (assuming the two spans don't overlap). Performance Improvement As part of the development of these new APIs, we did of course write performance tests and the results really speak for themselves: transforming one million points with the new batch APIs resulted in performance ranging from 16x the original speed to just over 150x! Note though that you don't need to be transforming thousands of points to get a win here. While the existing APIs are fine for single instances, if you have even a few points to transform, the odds are it will be faster to use the batch APIs with the difference increasing as the size of your data set grows. Batch Gizmo Line Drawing APIs Also in 2023.1 are two new batch APIs for the Gizmos class extending its current line drawing abilities to allow multiple lines to be drawn in a single API call. Currently, for drawing simple lines the Gizmos class offers the DrawLine() API Gizmos.DrawLine() this API simply takes two Vector3 instances representing the beginning and end of the line to draw and does exactly that. However, in a manner identical to the Transform APIs described above, if you need to draw a large number of lines (maybe a curve made up of line segments for example or some other complex gizmo visualization), you need to repeatedly call it with each pair of endpoints incurring the data marshalling and managed/native transition overhead cost each time. To avoid this the new APIs in 2023.1 give you a better option in this situation: Gizmos.DrawLineList() Gizmos.DrawLineStrip() both of these APIs take a Span<Vector3> containing a sequence of line endpoints and draw multiple lines using them. The former DrawLineList() draws a single line between each pair of points allowing a sequence of disconnected lines to be drawn while the latter DrawLineStrip() draws a connected sequence of lines between each point in turn (so a line from point to point, then another from point to point and so on) and also takes an optional flag to have an additional line drawn between the last point and the first to "close" the loop. Performance Improvement Again, as you would expect, we ran performance tests for the new APIs and the results are clear: Here we can see it's about 14x faster to use the batch APIs purely due to the reduction in API call overhead, and again you don't need to have massive data sets to benefit. If you have even a few lines to draw the odds are it will be faster to use the new batch APIs than the existing single line one. Final Words This post was written to help highlight these new APIs that are available in 2023.1 as they provide such an enormous performance gain in the common situation where larger data sets are being worked on. Work is underway to backport them to the 2022 stream in time for LTS so they should be available there in due course to further expand their utility.