NativeArray<T> is great, but very limited in functionality. We can fix this surprisingly easily! Today we revive a two year old series that created the iterator project. Iterators are like a no-GC version of
IEnumerable<T> and LINQ which have a lot of power but only support managed arrays (
List<T>. Today we’ll add support for
NativeArray<T> and inherit support for the same functionality. We’ll also spruce up the project with proper unit tests, assembly definitions, and runtime tests to confirm that zero garbage is created. Read on to see how this was done and how to use iterators with
Posts Tagged array
It’s been over three years since the last article on LINQ performance. That was all the way back in the Unity 5.0 days using Mono as a scripting backend. Today we’ll update that article’s test with Unity 2018.1 and IL2CPP to see how LINQ fares these days. Is it any better? Read on to find out!
There are many permutations of loops we can write, but what do they compile to? We should know the consequences of using an array versus a
Length, and other factors. So today’s article dives into the C++ code that IL2CPP outputs when we write these various types of loops to examine the differences. We’ll even go further and look at the ARM assembly that the C++ compiles to and really find out how much overhead our choices are costing us.
C++ doesn’t have a
foreach keyword, but it does have an equivalent in “range
for loops”. Today we’ll implement support for them so we can easily loop over arrays and types implementing
The last time we looked at performance was way back in part four of the series. Ever since then we’ve been relentlessly adding more and more features to the C++ scripting system. So today we’ll take a break from feature additions to improve the system’s performance in a couple of key areas.
The series continues by adding support for a major feature: arrays. These are used very frequently throughout the Unity and .NET APIs and the lack of support for them has been a big missing piece of the puzzle for most games. The GitHub project has been updated to support single- and multi-dimensional arrays. Read on to learn how this support was implemented!
Every time I see
for (var i = 0; i < array.Length; ++i) I wonder if accessing that
Length property is slow. Should I cache it? It’s comforting to know that
for (int i = 0, len = array.Length; i < len; ++i) is only dealing with local variables except on the first loop. Local variables must be faster, right? Likewise, I wonder the same thing about
List<T>.Count. I finally got around to running a test to see if caching these length properties makes any performance difference. The answers might surprise you!