Generic Math at Raw Operator Speed 02 December 2020 Tips and Tricks If you need the absolute fastest way to do generic math operations in C# then this is the way to do it. When the JIT compiler processes this method for a particular type, there are a number of clever optimizations that happen which allow it to run at raw operator speed. [More]
Fastest Possible Thread-Safe Lock-Free Lookup Dictionary (CopyOnWriteDictionary) 12 November 2018 I have been writing a ton of code lately that involves permanently caching objects of various types: generated type schemas, compiled expression queries, reflection lookups for MethodInfo or PropertyInfo, etc. Usually these are updated infrequently in quick bursts, i.e. at application startup, when a new assembly loads, or when a new operation is invoked for the first time that makes use of items that haven't been cached yet. I always felt like the existing options were lacking in usability and/or performance and we could do much better - CopyOnWriteDictionary is the culmination of that pursuit and represents what I consider the ideal dictionary implementation for use cases like this. [More]
Value Type Box Cache 23 November 2017 Tips and Tricks We've recently been building a .NET object database that necessarily stores a lot of data in object[] arrays. Most of the values in these arrays are default values (i.e. 0 for numbers), small integers, boolean values or enums. On a loaded instance there can be many millions of these boxes values sitting in memory and they are constantly being created and collected, which got me thinking...we could probably cache and reuse the boxes for a lot of these values, and thus the BoxCache was born! [More]
Updated Ultimate WPF Event Method Binding 25 September 2016 After we started using our MethodBinding, we quickly ran into a few use cases that it could not accommodate very well so we ended up changing it a bit. This isn't going to be a long post, it is just going to cover the changes we made since the original article was posted. [More]
Getting Rid of Ugly TransformGroup Blocks in WPF 05 July 2016 Tips and Tricks If you're obsessed with beautiful and clean XAML code like I am, a real thorn in your side is seeing large ugly TransformGroup blocks in your code. Here's how to fix that. [More]
Building the Ultimate WPF Event Method Binding Extension 05 July 2016 Tips and Tricks Seeing that .NET 4.5 added support in WPF for markup extensions on events, I looked around to see what was out there in terms of method binding support. I couldn't find anything that quite did everything I needed, so I set out to build the ultimate method binding extension. [More]
WPF Visibility Binding with Design Time Control (and more!) 04 July 2016 Tips and Tricks Designers don't want to worry about how to modify view models when designing a UI. They just want to show and hide elements to see what they look like, and occasionally test out a few different values to make sure it still looks correct. The current methods are too complicated to setup or to cumbersome to work with for simple tasks. Here's an alternate approach. [More]