Today we’ll wrap up the iterator series by finishing up porting C++’s <algorithm> header. We end up with a library of functions for common LINQ-style algorithms but without any of the garbage creation that slows our games down. Read on for the source and examples!
Posts Tagged performance
We’re nearing the end of the series to build a no-garbage replacement for
System.Linq. Today we tackle functions that work on already-sorted ranges and functions that work on ranges that are in heap order. These include common set operations like “union” and “intersection”. Read on to see how to use them and for the updated library that you can use to eliminate your garbage creation!
Back from a brief break, we pick up this week by finishing up the “modifying sequence operations” with some gems like
RandomShuffle and go through the “partitions” category with functions like
IsPartitioned. These are all solid algorithms with a lot of potential uses, so read on to see how to use them with iterators and for the source code that implements them!
Today’s article takes a break from the iterator series to investigate an interesting anomaly with the
List.ForEach function: it’s surprisingly fast! So fast that it’s actually competitive with regular old
while functions. How can it be so fast when it has to call a delegate that you pass it for every single loop iteration? Read on for to find out!
Last week’s article introduced the concept of iterators as an alternative to the GC-heavy
IEnumerable. Today’s article expands the iterator library to include a bunch of more functions to make it useful. Think of these like the extension functions in
IndexOf, etc. These have all been tailored to iterators and none of them will create any garbage whatsoever.
In C#, just about everything is an
IEnumerable. Since LINQ syntax,
foreach loops, and the
System.Linq namespace are all designed to work with
IEnumerable, you’ve got lots of tools to use. Unfortunately, the core of
IEnumerable is the
GetEnumerator function which usually creates garbage and eventually causes memory fragmentation and GC framerate spikes. Do we simply stop using all of these nice tools? Normally the answer is “yes”, but today’s article shows you another way.
Last time we saw that calling a non-default constructor on a generic struct (
MyStruct<T>) causes garbage creation. That garbage creation is subtle, but can have big impacts on framerate and memory usage. Today we’ll see two more ways that structs can create garbage and hopefully avoid some pitfalls. Read on to find out how!