Build 2019

Here are the build videos from 2019, that I suggest for watching (besides the keynotes). These sessions mostly focus on serverless, microservices, .net and C# topics. This list does not include the keynotes.

.NET and C#

Serverless and Blazor

Find out more


Deep Dive in Ref Returns

In the previous post I have used Ref returns to return some data. I noticed that with slight changes we get totally different code generated by the JIT, which is can have a good or bad effect on our code.

In this post, I will dig deep (with WinDbg) in the JIT generated code. As forefront: I am using 64 bit machine, .net core 2.1 and RyuJIT.

I created a sample benchmark to showcase. I have a Point struct with 2 integer properties. I benchmark setting the values on the struct in 3 different ways, I show related IL and machine code impacting performance.

The benchmark

Find out more


The power of Span

Intro to the problem

In one organization, I had to schedule a regular meeting once a week, that fits most the people. Fortunately, the people in this organization mark their holidays in a csv file, so processing the file can help me to figure the day when the least favorable for holidays.For this I would like to have a table which shows the given weekday, and the number of holidays taken on that day.

As a note, we can assume people include public holidays to the time interval in the file, as they usually do so. They also include Saturdays and Sundays too, but those will be filtered out.

Fortunately, we can have two solutions for this problem. On is the classic solution in the 'old' C# way, and one new solution from the Span era of dotnet with a more efficient solution.

Find out more


Ref Returns

C# has recently introduced some new features (version 7.0) one of which it is ref returns. I will use this feature in this post to further improve the performance of the Parser created in my previous post.

To refresh the Parser class looked as follows:

public class Parser 
{
  public T Parse<T>(ReadOnlySpan<char> input, PropertySetter[] setters) where T : struct
  {
    T result = default;
    int separator;
    int propertySetterIndex = 0;
    while((separator = input.IndexOf(',')) != -1)
    {
      var parsedValue = int.Parse(input.Slice(0, separator));
      setters[propertySetterIndex++].SetValue(ref result, parsedValue);
      input = input.Slice(separator + 1);
    }
    return result;
  }
}

To recap it receives an input of comma separated integers that we are parsing into a struct of the user's choice: T. Extending it to other than integer types and fixing the possible ArgumentOutOfRangeException is not a concern of this blog post.

Find out more


Heap Allocation free Parsing: structs

I have been working on a library RapideFix to parse fix messages. One of the challenges is to parse a message into a struct with the least amount of allocations possible. That means to allocate only for the references (if any) that are part of the struct's fields.

For the sake of this post, I will use a very simple struct with 2 integer properties and the parser method will set values to them. However, the code should be dynamic, so the user can replace the struct to any other custom one.

Starting Point

So, let's start with a sample code, which is incorrect after all, but it demonstrates what I want to achieve (if it worked correctly).So what I want to do is that given a string with two integers separated by commas "20,19,", and the parser should set the integer values on a struct, Point:

Find out more