Generating PInvoke code for Win32 apis using a Source Generator

  • Gérald Barré
Writing PInvoke code is not trivial. Most of the time you need to find the method signature from the documentation or the header files. This takes time and is error prone. Also, you can't find a NuGet package that wraps all Win32 methods because the number of methods, constants and structures is huge. Hopefully, Microsoft has released a Roslyn source generator to generate PInvoke for Win32 apis. In this… [read more]

Using a custom build pipeline with Azure Static Web Apps

  • Gérald Barré
Azure Static Web Apps allows to host static web sites and their API. They also provide a GitHub action to build and deploy your application. The GitHub action automatically detects the kind of project from the sources and builds it. It currently supports many JavaScript frameworks and static site generators like Hugo, Gastby, Angular, React, Svelte, Vue, or Blazor. While this magic works most of the time,… [read more]

Faster and Safer NuGet restore using Source Mapping and Lock files

  • Gérald Barré
Using NuGet packages is very common. Some options may help get better performance and security when restoring packages. Lock Files When restoring packages, NuGet creates a dependency graph. This graph includes all declared packages and the transitive packages. This dependency graph is then used to determine which packages should be downloaded and installed. A lock file allows to store the dependency graph… [read more]

Running Lighthouse CI when deploying Azure SWA

  • Gérald Barré
When you add new features to a web application, it's important to ensure there is no regression in term of performance. LightHouse CI is a tool that helps you to run a Lighthouse analysis on your web application. If you don't know lighthouse, it's a tool that analyzes web apps and web pages and generate a report about performance and best practices. Lighthouse integrated into the dev tools of Chromium… [read more]

Using IAsyncEnumerable in a Razor component

  • Gérald Barré
IAsyncEnumerable<T> is a new interface that is used to fetch asynchronous data. For instance, you can use it to fetch data from a paginated REST API. Indeed, you will need multiple async http requests to get all data, so it matches this interface. Let's see how you can use a method that returns an IAsyncEnumerable<T> instance in a Razor component. @* ❌ This is not valid in a Blazor component as the… [read more]

Finding the maximum value in an array using vectorization

  • Gérald Barré
In the previous post, I described vectorization in .NET and how it can be useful to improve performance of algorithms. In this post, I'll explain how to use vectorization to find the maximum value of an array. The algorithm is already implemented in Enumerable.Max. You can find the original code on GitHub. I simplified the code to make it more readable and added comments to explain how it works. internal… [read more]

Faster Guid comparisons using Vectors (SIMD) in .NET

  • Gérald Barré
Comparing Guids in .NET is a very common operation. If operation is simple, but there is a way to optimize it 😃 I've discovered it while reading the changes in this PR. The idea is to use SIMD instructions to compare Guids. I've wanted to explore SIMD and Vector for quite a long time. So, this was a good introduction. In this post, I'll explain how the optimization works. How Guid.Equals() works A Guid… [read more]

Using Avif codec for images to reduce web page size

  • Gérald Barré
Images represent a large part of the internet traffic. Reducing the size of image files can help to reduce the amount of data that is transferred over the internet, and it may reduce the hosting costs of your website. And for the users, it can help showing images faster. AV1 Image File Format (AVIF) is a new image format developed by the Alliance for Open Media (AOM). AV1 is currently supported by Chrome,… [read more]