NancyFx vs. FeatherHttp
As a long time fan of the lightweight syntax of the awesome NancyFx web framework, I was really curious when I stumbled upon FeatherHttp, a new low-ceremony framework for building web services in .Net Core applications.
Naturally, I was curious not only about the syntax but about the performance as well. So I decided to compare their raw performance, using the awesome wrk2 tool.As a first step, I created two HTTP servers with one endpoint that does the same work in both cases.
NancyFx server c ...
More efficient string concatenation with string.Create()
Strings are immutable in C#, this is a common knowledge. Unless you use pointers in unsafe blocks, that is. Apparently, there is another way of making strings mutable.When I discovered string.Create(), a not-so-new but for some reason overlooked (by me at least!) method that was added since .Net Core 2.2 and Netstandard 2.1, I was really curious how it works (and how well it works too), so I looked at relevant .Net Core source code.
12345678910public static string Create<TState>(int lengt ...
Reasons for C# inlining are (a bit) more complex than you think.
The Twitter sometimes can serve as a place of unexpected insights and very interesting technical questions! For example, the question asked in a tweet here: https://twitter.com/EgorBo/status/1236324907723771904
Apparently, in the following code, C# compiler will inline Test1 and not Test2
12345678910111213141516171819using System;public static class C{ public static void Test1() { Validate(42, 42); } public static void Test2(int a, int b) { ...
Local variables vs properties. No suprises here?
Can the benchmark that compares array iteration vs. pointer based iteration be optimized further? Yep!In a post I wrote earlier about performance comparison between array access with pointers and the usual C#’s way, I saw an interesting comment that suggested a way to squeeze some more performance out of the scenario.Using a local variable instead of a call to a property (which is in fact a method call) made sense, though I wondered, just how much of a performance boost it would provide.So I de ...
Is it faster to access arrays with pointer arithmetics?
After seeing the results of my previous post where I tested performance impact of data locality, one of my collegues theorized that perhaps the huge difference between C++ and C# performance (assuming adjacent memory iteration) is due to boundary checks of C# arrays - he said that if I would use pointers to access arrays, the code will be much faster. I was curious if he was right, so I tested it.
The testI used the following test to try and see how much performance usage of pointers over simple ...
Easy way to configure SOS in LLDB
I don’t have much experience in using LLDB to debug .Net Core, so when I stumbled upon this little gem while looking at dotnet/diagnostics GitHub repository, I was instantly curious to try it: up to this point, in order to load the SOS plugin, I had to manually look up its folder, then specify it inside LLDB (via the load plugin command).This tool, however, should configure LLDB to load SOS plugin automatically!How? First install the tool via .Net Core CLI:
1dotnet tool install -g dotnet-so ...
Sequential memory access is... faster?
In gamedev articles about Entity-Component-System, data locality is often mentioned as a big reason to use such design pattern. The underlying data structures of the ECS are cache friendly, thus allowing much better performance for iterations of large amount of game objects.I knew that cache-friendly usage of memory (sequential memory access, for example) would yield better performance, but I was curious, how much better it would be?
In case you never heard about Entity-Component-System, this a ...
Nice little gotcha when loading SOS after launching .Net executable
When you launch .Net executable with WinDBG, in order to “catch” something nasty like AccessViolationExcetion, the application will stop after loading with a “debugger break”, and you will see something like this:
123(6b8.37dc): Break instruction exception - code 80000003 (first chance)ntdll!LdrpDoDebuggerBreak+0x30:00007ffc`391d121c cc int 3
At this point, if you try to load SOS, you will see an error.
120:000> .loadby sos coreclrUnable to find module 'coreclr'
Th ...
Setting up WinDBG for analyzing memory dumps
When I needed to investigate a memory dump for a first time, I stared at WinDBG window, not knowing how to begin. My google-fu yielded mixed results - I had to sift through lots of information, sometimes incorrect, sometimes outdated, only after some experimentation, I was able to actually understand what was going on.Though, in a hindsight, WinDBG is much less complex than it seemed in the first place.
A word (or three) on WinDBGWinDBG wikipedia article states that WinDbg is a multipurpose deb ...
Segmentation faults when using P/Invoke = pointer issues? Not necessarily
When debugging new RavenDB’s 32-bit pager for Linux-based ARM environments, which has platform specific functionality implemented in C and P/Invoked from C# code, I ran into an issue: when starting, RavenDB was throwing a segmentation fault and crashing. Since the C# code didn’t change much, my immediate suspect was some sort of pointer issue in C code, such as trying to dereference a null pointer.
GDB is awesome for handling segfaultsThe GNU Debugger or GDB is very good at tracing such is ...