| Great list. It's important to understand when to use each one of these. Identify your bottleneck, through the use of profilers. Execution time is largely based on memory bus blocking I/O and not the CPU calculations, so if you start with writing SIMD, you're not going to get anywhere. Accessing data on the stack instead of the heap is the #1 saver of execution time, in my experience. But your bottlenecks might be different. Locally scoped value-type variables are generally on the stack. Object-scoped and static fields and properties are on the heap. Writes to local variables seem to be faster than reads, IIRC.
The fastest operators seem to be the bitwise instructions, IIRC.
If running in 32-bit mode, try to work with 32-bit integers. If running in 64-bit mode, try to work with 64-bit integers. Here's an example of a major, major improvement in performance for(int x = 0; x < this.Width; x++) { for(int y = 0; y < this.Height; y++) { foo = bar; }
}Much faster version (due to storing a copy of Width and Height on the stack instead of the heap): int width = this.Width; int height = this.Height; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { foo = bar; }
}My comment here describes roughly the approach I used to take advantage of stack-allocated memory (before Span<T> was available). https://news.ycombinator.com/item?id=15136627 |