Sergey Tepliakov

Senior Software Engineer, Tools for Software Engineers

Lead software developer and software architect. Specialties: C#, C++, OOD, Design Patterns, Unit Testing, Multitheading, TPL

Post by this author

Extending the async methods in C#

The async series 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# compiler provides for customizing the behavior of async methods. There are 3 ways how you can control the async method's machinery: Custom...

Dissecting the async methods in C#

The async series The C# language is great for developer's productivity and I'm glad for the recent push towards making it more suitable for high-performance applications. Here is an example: C# 5 introduced 'async' methods. The feature is very useful from a user's point of view because it helps combining several task-...

Dissecting the tuples in C# 7

types were introduced in .NET 4.0 with two significant drawbacks: (1) tuple types are classes and (2) there was no language support for constructing/deconstructing them. To solve these issues, C# 7 introduces new language feature as well as a new family of types (*). Today, if you need to glue together two values to return them from a ...

Dissecting the pattern matching in C# 7

C# 7 finally introduced a long-awaited feature called "pattern matching". If you're familiar with functional languages like F# you may be slightly disappointed with this feature in its current state, but even today it can simplify your code in a variety of different scenarios. Every new feature is fraught with danger for a developer working...

Dissecting the local functions in C# 7

The Local functions is a new feature in C# 7 that allows defining a function inside another function. When to use a local function? The main idea of local functions is very similar to anonymous methods: in some cases creating a named function is too expensive in terms of cognitive load on a reader. Sometimes the functionality is inherently ...

Managed object internals, Part 4. Fields layout

In the recent blog posts we've discussed invisible part of the object layout in the CLR: This time we're going to focus on the layout of an instance itself, specifically, how instance fields are laid out in memory. (image) There is no official documentation about fields layout because the CLR authors reserved the right ...

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. Today you may use them less ...

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 created lazily ...

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. (image) The first time I’ve read about it, I’ve got a question: why the layout of an object is so weird? Why a managed ...

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: (*) Our ...