Daniel Crabtree https://www.danielcrabtree.com/blog Daniel Crabtree Copyright (c) Daniel Crabtree 2003 - 2017 Maximizing Throughput - The Overhead of 1 Million Tasks https://www.danielcrabtree.com/blog/248/maximizing-throughput-the-overhead-of-1-million-tasks Tue, 02 May 2017 08:45:00 GMT <p>I recently needed to choose between two competing designs: a simple one that needed millions of tasks or a complex one that needed only a few processing threads.</p> <p>Plan A was to leverage the power of Task-based asynchronous programming in .NET to create a simple solution that had tasks waiting on a mix of other tasks, timers, events, and more; but, it would need millions of tasks, all &hellip;</p> https://www.danielcrabtree.com/blog/248/maximizing-throughput-the-overhead-of-1-million-tasks Better Benchmarking with Additive and Multiplicative Baselines https://www.danielcrabtree.com/blog/234/better-benchmarking-with-additive-and-multiplicative-baselines Sat, 22 Apr 2017 03:14:00 GMT <p>In my recent blog posts I've been benchmarking different ways to cast in C#. If you have a keen eye, you may have noticed that the results do not match up. In one experiment, a <a href="/blog/214/covariant-and-contravariant-casting-is-3x-slower-than-dynamic">direct cast</a> (no cast at all) takes 15ns, while in another experiment, a more complicated <a href="/blog/191/casting-to-ienumerable-t-is-two-orders-of-magnitude-slower">generic cast</a> &hellip;</p> https://www.danielcrabtree.com/blog/234/better-benchmarking-with-additive-and-multiplicative-baselines Covariant and Contravariant Casting is 3x Slower than Dynamic https://www.danielcrabtree.com/blog/214/covariant-and-contravariant-casting-is-3x-slower-than-dynamic Wed, 19 Apr 2017 13:10:00 GMT <p>Previously, we saw that <a href="/blog/191/casting-to-ienumerable-t-is-two-orders-of-magnitude-slower">covariant and contravariant casting is slow</a>: 100x slower than normal casting. It turns out that covariant and contravariant casting is even slower than casting to <code>dynamic</code> and using dynamic dispatch: 3x slower than dynamic. This is significant as <code>IEnumerable&lt;T&gt;</code> &hellip;</p> https://www.danielcrabtree.com/blog/214/covariant-and-contravariant-casting-is-3x-slower-than-dynamic Casting to IEnumerable<T> is Two Orders of Magnitude Slower https://www.danielcrabtree.com/blog/191/casting-to-ienumerable-t-is-two-orders-of-magnitude-slower Thu, 13 Apr 2017 17:20:00 GMT <p>Casting to generic interfaces that use covariance or contravariance is two orders of magnitude slower than normal casts in C#. This means casting to <code>IEnumerable&lt;T&gt;</code> is two orders of magnitude slower too. This result was quite unexpected and very surprising.</p> <p>In this post, I investigate the cost of casting to implementations, interfaces, generic interfaces, covariant &hellip;</p> https://www.danielcrabtree.com/blog/191/casting-to-ienumerable-t-is-two-orders-of-magnitude-slower How to fix Fatal Error with Git in Visual Studio 2017 https://www.danielcrabtree.com/blog/176/how-to-fix-fatal-error-with-git-in-visual-studio-2017 Sun, 09 Apr 2017 15:54:00 GMT <p>Every update I've applied to Visual Studio 2017 has broken Git again. Until 15.1 (26403.0), the solution was to delete Visual Studio's version of Git and let it pick up the version installed in Windows. I documented this in my post on <a href="/blog/42/gotchas-with-upgrading-to-visual-studio-2017">troubleshooting the Visual Studio 2017 upgrade</a>.</p> <p>The problem manifests itself when you &hellip;</p> https://www.danielcrabtree.com/blog/176/how-to-fix-fatal-error-with-git-in-visual-studio-2017 C# 7: Micro-Benchmarking the Three Ways to Cast Safely https://www.danielcrabtree.com/blog/164/c-sharp-7-micro-benchmarking-the-three-ways-to-cast-safely Fri, 07 Apr 2017 16:43:00 GMT <p>As we saw in my previous post, there are <a href="https://www.danielcrabtree.com/blog/152/c-sharp-7-is-operator-patterns-you-wont-need-as-as-often">three ways to cast safely</a> in C# 7. In this post, I micro-benchmark the three methods of safe casting and dive into the IL to understand the differences.</p> <p>The three methods of safe casting (from my <a href="https://www.danielcrabtree.com/blog/152/c-sharp-7-is-operator-patterns-you-wont-need-as-as-often">previous post</a> &hellip;</p> https://www.danielcrabtree.com/blog/164/c-sharp-7-micro-benchmarking-the-three-ways-to-cast-safely C# 7: Is Operator Patterns - You won't need 'as' as often https://www.danielcrabtree.com/blog/152/c-sharp-7-is-operator-patterns-you-wont-need-as-as-often Thu, 06 Apr 2017 09:02:00 GMT <p>C# has long supported two operators to check the type of an object: <code>is</code> and <code>as</code>. C# 7 adds a new way to use the <code>is</code> operator that combines <code>is</code> with basic patterns to provide an alternative for <code>as</code>.</p> <p>The new <code>is</code> patterns provide a nicer syntax for safe casting than both the existing <code>is</code> and <code>as</code> &hellip;</p> https://www.danielcrabtree.com/blog/152/c-sharp-7-is-operator-patterns-you-wont-need-as-as-often Cannot Go To Definition on Generic Types in VS2017 https://www.danielcrabtree.com/blog/137/cannot-go-to-definition-on-generic-types-in-vs2017 Tue, 04 Apr 2017 23:36:00 GMT <p>Go To Definition in Visual Studio 2017 has been bugging me for a while now. When I try to Go To Definition on some types, VS2017 pops up with an error &quot;Cannot navigate to the symbol under the caret&quot;. Today, I decided it was time to try and figure it out.</p> <p>This is not the first time this has happened and there are lots of people who experienced a similar error on VS2015. &hellip;</p> https://www.danielcrabtree.com/blog/137/cannot-go-to-definition-on-generic-types-in-vs2017 C# 7: Ref Returns, Ref Locals, and how to use them https://www.danielcrabtree.com/blog/128/c-sharp-7-ref-returns-ref-locals-and-how-to-use-them Fri, 24 Mar 2017 15:53:00 GMT <p>C# has always supported the ability to pass by reference using the <code>ref</code> keyword on method parameters. C# 7 adds the ability to return by reference and to store references in local variables.</p> <p>The primary reason for using ref returns and ref locals is performance. If you have big structs, you can now reference these directly in safe code to avoid copying. Before C# 7 you had &hellip;</p> https://www.danielcrabtree.com/blog/128/c-sharp-7-ref-returns-ref-locals-and-how-to-use-them C# 7: Dynamic types and Reflection cannot access Tuple fields by name https://www.danielcrabtree.com/blog/99/c-sharp-7-dynamic-types-and-reflection-cannot-access-tuple-fields-by-name Sun, 19 Mar 2017 09:49:00 GMT <p><a href="https://www.danielcrabtree.com/blog/17/c-sharp-7-preview-using-tuples-to-return-multiple-values">Tuples</a> are a great new feature in C# 7 and I've used them a few times already. The syntax is great, they're easy to use, and they're a whole lot better than the alternatives.</p> <p>Tuples are implemented using <code>ValueTuple</code>, with <a href="https://github.com/dotnet/roslyn/blob/master/docs/features/tuples.md#name-erasure-at-runtime-">name erasure at runtime</a> &hellip;</p> https://www.danielcrabtree.com/blog/99/c-sharp-7-dynamic-types-and-reflection-cannot-access-tuple-fields-by-name