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


ETW Logging implementation for Service Fabric

ETW Logging is suggested for Service Fabric application. ETW has numerous advantages, but the biggest one is being extremely fast.

Preamble

This is poor man's logging. Consider using existing libraries in production applications, such as EventFlow.

The EventSource

Find out more


Perfomance of Mapping C# Poco objects 1

In the series of the following posts, I will explore a couple of ways to map one object to another object, and will measure the performance of these methods.

The task will be map 2 types to each other:

public class People1
{
  public int Age { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public Guid Id { get; set; }
  public double Weight { get; set; }
  public double Height { get; set; }
  public string NationalId { get; set; }
  public God1 God { get; set; }
}
public class People2
{
  public int Age { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public Guid Id { get; set; }
  public double Weight { get; set; }
  public double Height { get; set; }
  public string NationalId { get; set; }
  public God2 God { get; set; }
}

public class God1
{
  public string Name { get; set; }
}
public class God2
{
  public string Name { get; set; }
}

Measurement

Find out more


Memory dump with Nano server and Docker

In this post I will detail the steps to create a memory dump for an application which runs in a docker container on Windows Nano server.

Here, I would like to thank @gaborpro for his suggestions throughout the process.

Let's assume we have a .net core application being developed, the application will run in a container based on an image with Windows Nano. At some point we will need to create a memory dump of our application to investigate performance issues. To get started a tool (an exe) needs to be available in the container for creating the dump file. There are several ways to achieve this:

  1. Include the tool along with the application (COPY it in the dockerfile)

  2. Extend the base image

  3. Use docker cp command to copy it (if the command is supported on your platform)

  4. Map an external drive (as a volume) with the tool available on the drive

Find out more