Posts

Distributed Isolator

Introduction The purpose of Isolator , my framework for running isolated (sandboxed) code is to be able to, well, run code (known as plugins) on distributed, isolated instances (hosts). I initially created two isolation hosts: Process ( ProcessIsolationHost ): a new process is created to host and run the plugin Assembly Load Context ( AssemblyLoadContextIsolationHost ): a new assembly and assembly load context are created to host and run the plugin Now I'm introducing a new one, that allows to execute code on another machine:  ClientIsolationHost . I'll show you how to use it now. Client Host Isolation The idea is to be able to run code on a different machine, while keeping the same capabilities: We pass an existing plugin instance to the host which is then handled transparently Modified context properties are returned from the host to the caller Standard output and error are also returned The result value from the plugin's execution is returned...

Working with Strings in .NET

Introduction So, by now you should know all there is to about string concatenation  in .NET and the  StringBuilder  class and the  string.Concat  method. I'm not going to cover that here, but, instead, some less known functionality around strings that can (also) bring some performance advantages. Searching When it comes to searching for values ("needles") inside a string ("haystack"), we have a couple options: Using the built-in string methods, such as  string.IndexOf , string.IndexOfAny , string.Contains The ContainsAny extension that works with memory spans Using regular expressions with  Regex , for more advanced pattern matching Since .NET 8, we have another one: the  SearchValues<T>  class. This one is optimised for searching for one or multiple strings (exact values) inside of a string. During its creation, it parses the string and builds a memory model that is suitable for searching. With time, using  SearchValues<T...

Table Inheritance with EF Core

Image
Note: this is an update to an old post on my old blog . Introduction EF Core 7  finally delivered a long-sought desire: all of the three  table inheritance patterns  are now implemented. These are: Table Per Hierarchy  ( TPH ) /  Single Table Inheritance : all columns for the properties of base and all derived classes are stored on the same, single, table, one for each base class (implemented in EF Core 1); Table Per Type  ( TPT ) /  Class Table Inheritance : columns for the properties of each class (abstract or otherwise) are stored on an individual table, and linked to tables that contain the columns for the properties for each base class through foreign keys (EF Core 5); Table Per Concrete Type  ( TPC ) /  Concrete Type Inheritance : a table exists for each concrete class which contains columns for each property of that class (EF Core 7). All of these patterns were discussed at length on  Martin Fowler ’s book,  Patterns of Ente...

Optimising EF Core

Note: this is an update to an old post on my old blog . Introduction We all know O/RMs aren't the fastest tools when it comes to loading data, and Entity Framework Core is surely no exception. After all, they need to do a lot of operations, such as translating LINQ queries to SQL, instantiating the right entities, hydrating them (setting their properties from the database-retrieved values), taking a snapshot for the change-tracking functionality, etc, etc. But there, however, are a few things that we can do to help speed things a bit! Here are a few tips for you to make the best usage of Entity Framework Core, organised intro three topics: Optimising reads Optimising writes Other Optimising Reads Use Compiled Queries One of the things that can take some time is the translation from LINQ to SQL. This needs to happen all the time we execute a query from LINQ, unless, of course, we use a compiled query. Compiled queries are not exactly new in EF, and you can read...