August 14th, 2015, 10:06 pm
.NET Performance Tuning Tips1) Pre-complier NGEN install myapp.exe2) Use Value types (no heap memory)3) Rewrite (overload) methods so that they don't use boxing or reflection 4) Use Generic Collections to avoid boxing/unboxing costs5) Use fastest JIT compiler, RyuJit > JIT64 , use RyuJit for faster compilation time6) MPGO (Managed Profile Guided Optimization) Improves precompiled assemblies' disk layout- Optimize code and data positions on disk7) Improve Cold Startup I/O time,- ILMerge , merge dlls with .exe into a new .exe file 8) Improve Cold Startup I/O time - Executable packers - compress assemblies so that they take less to load - RugLand packer (RPX , codeplex)9) Improve Cold Startup I/O time - Place Strong named assemblies in the GAC so that the CLR can skip the assembly verification checks.10) Improve Cold Startup I/O time- Windows SuperFetch Pre-Fetch code and data that it thinks your app will need.11) Precompile serialization assemblies - SGen.exe12) Precompile Regexes13) Use Unsafe code - Pointers and Memory pinning to avoid garbage collection14) Hand rolled memory copy methods using pointers sometimes it's faster for certain array sizes.15) Use Dynamic code to construct dynamic unsafe generic methods and classes using pointers and IL code.16) Use array storage for speed and low memory usage17) Use LIST<T> , as a dynamic resizable array , but only use it with append to add data to the end of the array, other insertions will cause a full copy of the array when it runs out of current space and needs to resize.18) Use SortedDictionary<K,V> or SortedSET<T> for fast searching, needs a lot of memory.19) USE Hashing with Associative Collections. Dictionary<K,V> and HASHSET<T> provide O(1) insert, delete, and lookups, but will need time to reorganize if you make a lot of changes to them. CANNOT SORT BY KEY AND HAS BIG MEMORY OVERHEAD.20) Data Parallelism 21) Asynchronous I/O and Asynchronous Parallelism- Asynchronous file read, Asynchronous HTTP Post, Wait for all tasks to complete, Wait for first task to complete22) Get rid of high level synchronization locks by replacing with low level atomic synchronization primitives (using hardware-based inter-lock compare exchange exposed by C#) - used by Concurrent Stack and Concurrent Bag23) Aggregation- Instead of locks, use smaller unlocked sub-tasks and the re-combine all the outputs when the last sub-task is finished. Basically collect intermediate results into thread-local structures. Only need synchronization when combining thread-local outputs into one global output.24) Use Atomic hardware primitives: Interlocked.Increment, Interlocked.Decrement, Interlocked.Add etc..25) Parallel Loops for CPU Bound Workloads, Tasks, Async, and Wait for I/O Bound Workloads.
Last edited by
AnalyticalVega on August 20th, 2015, 10:00 pm, edited 1 time in total.