All posts with Tag Performance

Preview image blogpost

Be careful with ToListAsync and ToArrayAsync in Entity Framework Core

Entity Framework has two methods for converting a query to a list or an array: ToListAsync and ToArrayAsync. Of course there is also the sync version of these methods: ToList and ToArray. And sometimes, you should use the latter one!

Read the whole article

Preview image blogpost

ToArray(Async) vs ToList(Async) in Entity Framework 8

When retrieving data from your database with Entity Framework, there are two major options: ToArray and ToList. Besides the different return type, is there any significant difference in performance between the two? Let's find out!

Read the whole article

Comparing the performance between the Minimal API and classic Controllers

Today, we are going to benchmark the performance of the Minimal API in ASP.NET 9 (and for reference against ASP.NET 8 as well) against the classic Controllers. We will test a few scenarios and check how the performance of the Minimal API compares to the classic Controllers. Let's get right into it!

Read the whole article

.NET 9 LINQ Performance Edition

As with almost every edition of .NET, the team has been working on improving performance. In this blog post, we will see some improvements to the related tickets and benchmarks.

Read the whole article

Preview image blogpost

Does readonly make your code faster?

In this blog post we will discover whether or not the readonly modifier can make your code faster. So without further ado let's get started.

Read the whole article

Preview image blogpost

Performance (ReadOnly)List vs Immutable collection types

A bit back on LinkedIn, there was a discussion about read-only collection and immutability where this is not the point I want to discuss now, as I already covered that here: "ReadOnlyCollection is not an immutable collection".

This post is just about the performance of those types compared to our baseline, the good old List<T>. It also explains why we see the results we see.

Read the whole article

How to enumerate through a StringBuilder

Did you ever wonder how we can iterate through a StringBuilder? I mean, of course, we can just call ToString and use the returned string, but that means we materialize the whole thing without good reason.

We can also use a normal for-loop. But we can also find a completely different and probably dumber way! And if you wonder: No, this is not something you do in your daily life, but by doing so, I can show some cool stuff C# and .NET offer.

Read the whole article

Preview image blogpost

"Use always a StringBuilder" - Internet myths

Use always a StringBuilder

That is what you can read from time to time. The basic idea is, that a StringBuilder is "better" to be defined.

Why are people telling that lie? Let's discuss this and see what it isn't true.

Read the whole article

local functions vs lambda expressions

.NET knows local functions and lambda expressions. You can almost take them interchangeably, but there are also some differences between them.

This article will show the differences between them.

Read the whole article

Preview image blogpost

Low-level struct improvements in C# 11

C# 11 brings some major improvements for structs. You remember Span<T>, which you couldn't create?

Now you can. C# 11 allows ref fields in a struct. Why this is a cool thing and what you can do with it, you will see in a minute.

Read the whole article

Preview image blogpost

EF7 - Bulk updates and Bulk deletes

Finally the long awaited bulk update and bulk delete feature is heading towards Entity Framework 7. So we will have a look how to use it and what might be some limitations.

Also I will have a quick look at the performance aspect, because this was the main driver for that feature.

Read the whole article

ObjectPool - Rent and return some instances

Just imagine a car pool: There is a dealer which bought the car and lent's it to you. After a while you will return this car where you got it from. Much like that works an ObjectPool in C#. You can rent an expensive object from the pool and when you are done with it, you just return it. Sounds beautiful, doesn't it?

Let's explore the advantages and disadvantages of a ObjectPools and how they work.

Read the whole article

Preview image blogpost

Tail-Recursion - Explained with the Fibonacci series

What is Tail-Recursion? We will discover this "special" form of recursion on the example of the Fibonacci series. Also we will check how much faster it is and why.

Read the whole article

Why are sealed classes faster in C#? And should I seal them?

In C# we can add the sealed modifier to a class to indicate that no one is allowed to derive / inherit from that class. Let's have a look at the compiler in certain scenarios what happens if you seal a class.

Read the whole article

Preview image blogpost

4 Different ways of creating an array

In this blog post I will show you 4 different ways of creating an array and how they differ from each other.

Read the whole article

Create a low allocation and faster StringBuilder - Span in Action

.NET ships a nice StringBuilder since the dawn of time or at least since the beginning of the framework itself. The intention is simple: If we need to concatenate a lot of strings we can't rely on the + operator as we introduce a lot of unnecessary allocations plus it is slow! That is where the StringBuilder jumps into the picture.

Why is that? Why is the StringBuilder better? And can we do better? Spoiler: Yes!

Read the whole article

Preview image blogpost

Using SSE in C# on the example of the sum of a list

SSE stands for Streaming SIMD Extensions. What does that exactly mean and how can we leverage that in our C# code?

This blog post will shed some light on this topic. Also we make a small comparison to PLINQ.

Read the whole article

Preview image blogpost

Blazor Performance Tuning - Good practices and advanced use cases

Blazor is a beautiful framework for building SPA's. One advantage is that those SPA's feel like native applications. We do not feel that stuff is necessarily loading. But for that we have to keep our code performant.

This guide will highlight some of the techniques to keep your Blazor app running smoothly. We will also cover some more advanced use cases.

Read the whole article

Heap, Stack, Boxing and Unboxing, Performance ... let's order things!

In this article I will shade some lights on some of the most used terms which seems very confusing especially for beginners: heap, stack and boxing and unboxing.

Furthermore we will also encounter internet wisdom like:

Value types get stored on the stack. Reference types on the heap

We discuss why this is wrong and what the hell performance has to do with it?

Read the whole article

Enum.Equals - Performance analysis

Did you know that you can spend 100x times longer depending how you compare your enums?

Of course we are speaking here in terms of nanoseconds but this story is much more then just numbers. We'll also talk about boxing and unboxing. So let's dive right into it.

Read the whole article

struct Performance

Let's have a small look into structs and how they work when using Equals and GetHashCode. Plus have a brief look into a new C# 10 feature: readonly record struct.

Read the whole article

Preview image blogpost

A story about boxing / unboxing and string interpolation in C#

A story about boxing / unboxing and string interpolation in C#. What has string interpolation to do with boxing / unboxing and what's the impact?

Read the whole article

An error has occurred. This application may no longer respond until reloaded. Reload x