Showing results for .NET Internals - Developer Support

Oct 1, 2018
2
0

The danger of TaskCompletionSource class

Sergey Tepliakov
Sergey Tepliakov

... when used with async/await. TaskCompletionSource class is a very useful facility if you want to control the lifetime of a task manually. I share a canonical example when TaskCompletionSource is used for converting the event-based asynchronous code to the Task-based pattern.

seteplia
Jul 17, 2018
2
1

Performance implications of default struct equality in C#

Sergey Tepliakov
Sergey Tepliakov

If you're familiar with C#, then you most likely heard that you should always override and for custom structs for performance reasons. To better understand the importance and the rationale behind this advice we're going to look at the default behavior to see why and where the performance hit comes from. Then we'll look at a performance bug that o...

seteplia
Jan 25, 2018
3
0

The performance characteristics of async methods in C#

Sergey Tepliakov
Sergey Tepliakov

The async series 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 C# compiler provides to adjust the behavior of async methods. Today we're going to explore the performance characteristics of async methods. As you should already know from the fir...

seteplia
Jan 11, 2018
2
2

Extending the async methods in C#

Sergey Tepliakov
Sergey Tepliakov

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 type...

seteplia
Sep 21, 2017
0
1

Managed object internals, Part 4. Fields layout

Sergey Tepliakov
Sergey Tepliakov

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. There is no official documentation about fields layout because the CLR authors reserved the right to change it ...

seteplia
Sep 12, 2017
0
0

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

Sergey Tepliakov
Sergey Tepliakov

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 freque...

seteplia
Sep 6, 2017
1
1

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

Sergey Tepliakov
Sergey Tepliakov

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 because no...

seteplia
May 26, 2017
1
1

Managed object internals, Part 1. The layout

Sergey Tepliakov
Sergey Tepliakov

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 weird? Why a managed reference points into...

seteplia
May 17, 2017
0
0

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

Sergey Tepliakov
Sergey Tepliakov

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 ValueTuple w...

setepliaCode Review
May 9, 2017
0
0

Garbage collection and variable lifetime tracking

Sergey Tepliakov
Sergey Tepliakov

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.’? The answer is: “It depends”. In debug builds this will never happen (as far...

seteplia