This sample case study zeroes in on physics collisions – hence the plain capsule and cuboid graphics above. Two different collision types were optimized here: Axis-Aligned Bounding Boxes (AABB) for character-wall collisions, and Radius-based for character-character collisions.

Handcrafting intrinsics that will beat the compiler isn’t simple, but this case study demonstrates various approaches to do just that. Performance improvement is more than a target – it’s a process. Once you reach the measure-optimize cycle, you can profile to see how long the routine takes, then make adjustments and time it again. Use Profile Analyzer, or put in your own timing, to accomplish this.

Now you can turn your attention to making adjustments. In the case study, we moved out of Burst jobs to Burst static functions, which made timing easier to achieve. In a final game job, asynchronicity is a great asset, even though performance timing adds a layer of complexity. For a real game, you’d use ProfilerMarker, ProfilerRecorder, and ProfileAnalyzer to time within jobs. But here, the move to Burst static functions actually helped force the changes needed for auto-vectorization. If jobs are set up to use NativeArrays of structs with Burst static functions, it becomes less complicated to use pointers for basic types. This breaks up the data into more easily vectorizable pieces. And once the [NoAlias] attribute is added to the pointers, it tells the compiler whether there was overlap in the data that the pointers were used for. In our case study, the performance of the normal Burst was so strong that it required some very good Neon coding to beat it. To fully leverage Neon, the two different collision types each required proper structuring of data and logic.

The vectorization works best when four or eight objects can be compared simultaneously, so that it completes the same operation for them at once (with the appropriate Neon command). The updated guide takes you through examples for maintaining maximum performance.

Source: Unity Technologies Blog