Caeden117 / ChroMapper

GitHub repository for ChroMapper, the Unity-based map editor for Beat Saber.
https://cm.topc.at/dl
GNU General Public License v2.0
295 stars 86 forks source link

Optimizations with Span<T> #510

Closed Caeden117 closed 5 months ago

Caeden117 commented 5 months ago

This PR optimizes accelerates various components of ChroMapper by taking advantage of Span<T>. Iterating over a Span<T> is noticeably faster, even when compared to iterating a List<T> using a for loop. In addition, Span<T> iteration does not allocate memory, unlike a foreach loop.

Made possible by UnityH4xx, a Unity library that uses custom written IL to expose the backing array of a List<T> as a Span<T>. This is official API in .NET 5 and later, but is unfortunately left out of .NET Standard 2.1.

The Only Thing They Fear is You is a good benchmark map if you want to compare performance improvements in this PR.

ChroMapper code that was touched by this PR: