The performance characteristics of async methods in C#

The async series Dissecting the async methods in C#. Extending the async methods in C#. The performance characteristics of the async methods in C#. One user scenario to rule them all. In the last two blog posts we’ve covered the internals of async methods in C# and then we looked at the extensibility points the…

3

Extending the async methods in C#

The async series Dissecting the async methods in C#. Extending the async methods in C#. The performance characteristics of the async methods in C#. One user scenario to rule them all. In the previous blog post we discussed how the C# compiler transforms asynchronous methods. In this post, we’ll focus on extensibility points the C#…

3

Managed object internals, Part 4. Fields layout

In the recent blog posts we’ve discussed invisible part of the object layout in the CLR: Managed object internals, Part 1. The Layout Managed object internals, Part 2. Object header layout and the cost of locking Managed object internals, Part 3. The layout of a managed array This time we’re going to focus on the…

3

Managed object internals, Part 3. The layout of a managed array

Arrays are one of the basic building blocks of every applications. Even if you do not use arrays directly every day you definitely use them indirectly as part of almost any library. C# has arrays from the very beginning and back in the day that was the only “generic”-like and type safe data structure available….

4

Managed object internals, Part 2. Object header layout and the cost of locking

Working on my current project I’ve faced a very interesting situation. For each object of a given type, I had to create a monotonically growing identifier with few caveats: 1) the solution should work in multithreaded environment 2) the number of objects is fairly large, up to 10 million instances and 3) identity should be…

6

Managed object internals, Part 1. The layout

The layout of a managed object is pretty simple: a managed object contains instance data, a pointer to a meta-data (a.k.a. method table pointer) and a bag of internal information also known as an object header. The first time I’ve read about it, I’ve got a question: why the layout of an object is so…

5

To box or not to Box? That is the question!

Discussions on reddit, hacker news. Recently I’ve noticed that the Equal method from our ValueTuple (*) struct generates significant memory traffic (~1Gb). That was a bit of a surprise to me. This struct is well designed and was used pretty heavily in many performance critical scenarios. Here how the struct looks like: public struct ValueTuple<TItem1, TItem2> :…

5

Garbage collection and variable lifetime tracking

Here is a seemingly simple question for you: Is it possible that the CLR will call a finalizer for an instance when an instance method is still running? In other words, is it possible in the following case to see ‘Finalizing instance.’ before ‘Finished doing something.’? internal class GcIsWeird{    ~GcIsWeird()    {        Console.WriteLine(“Finalizing instance.”);    }     public int data = 42;    …

4