The Is, As and the Is-As - WinDBG

In the previous post, I have investigated the performance implications of using the is and as keywords, including the new pattern matching syntax for the is keyword. Let me reference a previous work in this topic from Sasha Goldshtein, which motivated to do the investigation on the new pattern matching syntax of the is keyword: Micro-Benchmarking Done Wrong, And For The Wrong Reasons

In the previous post, I have measured performance with micro-benchmarking and took a look at the code, through ILSpy.

In this post I will take a look at the same code (invoking a non-inlined Work() method) but this time, I will use WinDBG and compare the native code generated by the JIT compiler.

JIT compiler's output may change with version updates of the framework, as this is an implementation detail to the CLR. The generated code also depends on the architecture of the system where we run our code. My test machine is x64 and uses RyuJIT compiler.

Find out more


The Is, As and the Is-As

C# has recently introduced with C# 7 a couple of new syntax sugars. I this post, I will investigate the new is keyword from IL standpoint and from performance standpoint. I will investigate by analyzing the generated IL Code and by micro benchmarking the instructions.

In my tests I repeat and measure the time it takes to run these instructions in a loop of 1000000000. I elimininate the best and worst case, and calculate an average on the rest.

The book Pro .Net Performance has a chapter on micro benchmarking the is and as keywords. It starts with a false assumption that the 'as' keyword is faster compared to the 'is', while the real conclusion of the chapter would be to consider all details of micro benchmarking to avoid making false assumption.I will have a simple 'My' class created for the tests. Note, the NoInlining attribute on the Work method to avoid any optimization when invoking the method.

public class My
{
  public int a = 0;
  
  [MethodImpl(MethodImplOptions.NoInlining)]
  public void Work() {}
}

Find out more


Cost of running a chatbot

I have been using bot framework to run an unpublished chatbot. My chatbot is unpublished, as it is only used by a handful of people for testing purposes. As of end of last year, bot framework went live, and depricated the previous way to store the bot's state. we need to provide a way to manage data state, we can implement IBotDataStore, or just simply use one of the provided solutions. I went by using the latter option, using the CosmosDB. The reason was that I wanted to take a closer look at Cosmos DB, which has great features. After a couple of months I took a look the detailed costs in my bill, and I was striked me by the fact, that CosmosDB is expensive for a chatbot being a test phase.

CosmosDB

A pre-tax of nearly 50 Euros seems quite high for an unpublished chatbot having a couple of requests a day.

I changed to table store instead, it meant to give another implementation to IBotDataStore:

Find out more


Perfomance of Mapping C# Poco objects 3

In the last part of this series I will come up with a more generalized way of mapping objects one to another.

In the previous episodes

In the previous posts we have used AutoMapper to map People1, People2 and God1, God2 types respectively to each other. I have seen it is very easy to use AutoMapper, but when doing a performance measurement, it was shown that it takes 237ms to run our test sample.

In the second post, we repeated the same measurement, but instead of using AutoMapper, we used poor man's type, and manually created an extension method to map each type to the other. This approach was significantly faster, the same test took only 40ms to run. It has a huge disadvantage on the other hand, each mapping method has to be written by hand, which is significant amount of work.

Find out more


Perfomance of Mapping C# Poco objects 2

In the series of these posts, I explore a couple of ways to map one object to another object, and will measure the performance of that. In the first part, I used AutoMapper. In this part I will use the poor man's solution by writing the mapping by hand. This has a couple of disadvantages, hence libraries like AutoMapper exists. But if someone is willing to sacrifice writing some extra lines of code, he can ditch a dependency to a library. In the previous post I mapped People and God objects, one to another. Let's see the same doing by hand:

public static People2 Map(this People1 source, People2 target)
{
  target.Age = source.Age;
  target.FirstName = source.FirstName;
  target.LastName = source.LastName;
  target.Height = source.Height;
  target.Weight = source.Weight;
  target.Id = source.Id;
  target.NationalId = source.NationalId;
  target.God = source.God?.Map(target.God);
  return target;
}
public static God2 Map(this God1 source, God2 target)
{
  target.Name = source.Name;
  return target;
}

The given solution uses extension methods. This is a good practice when we do not have the source or chance to modify the source or target objects (say because they are in a 3rd party library). Still extension methods give a convenient way using this method on an existing People1 typed object. One interesting part here is that this extension method expects the target object to be existing at the point of invocation, while when using AutoMapper we relied on the library to create the target objects. This is an important observation when measuring the performance, thus we have to include the object instansiaton as well:

target = source.Map(new People2() { God = new God2() });

Find out more