Skip to content

Instantly share code, notes, and snippets.

View NinoFloris's full-sized avatar

Nino Floris NinoFloris

View GitHub Profile
@NinoFloris
NinoFloris / threading-io.md
Created December 25, 2024 14:28
Threading and I/O developments

Background

There has been a renewed interest in architectural designs for threading and I/O in the last few years. Thread-per-core architectures and io_uring being of particular relevance. Popular in high throughput, low latency applications like web servers and databases, areas .NET is good at these days.

While Rust is generally taking the lead here - both in activity and performance - authors of similar software in .NET (e.g. Kestrel/ASP.NET Core/YARP, Garnet, Orleans, RavenDB) looking to experiment or offer these architectures to their users would quickly find it infeasible today due to a few simple realities: tight coupling to the thread pool in the async and I/O internals, and a strong doctrine of ConfigureAwait(false) use in libraries.

These prevent alternative designs from maintaining workload affinity. Even if I/O is not a concern and ConfigureAwait(false) would not exist, achieving significant performance gains may still be challenging. TaskSchedulers and SynchronizationContexts are genera

@NinoFloris
NinoFloris / code.fs
Last active November 1, 2018 14:30
OptionsFactory with func instead of new()
namespace Configuration
open System
open System.Runtime.CompilerServices
open Microsoft.Extensions.Options
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Configuration
type OptionsFactoryFromFunc<'TOptions when 'TOptions : not struct and 'TOptions : (new : unit -> 'TOptions)>
(factoryFunc: Func<'TOptions>,
@NinoFloris
NinoFloris / keybase.md
Created October 30, 2018 16:50
keybase.md

Keybase proof

I hereby claim:

  • I am NinoFloris on github.
  • I am ninofloris (https://keybase.io/ninofloris) on keybase.
  • I have a public key whose fingerprint is 0772 2EE9 8C00 2F36 922E 2C7C 622A 9882 5766 7DFB

To claim this, I am signing this object:

@NinoFloris
NinoFloris / OptionUnionConverter.fs
Created July 31, 2018 16:40
OptionUnionConverter for failure allowed conversions
// Written in 2018 by Nino Floris ([email protected])
//
// To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights
// to this software to the public domain worldwide. This software is distributed without any warranty.
//
// You may have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
namespace JsonConverters
@NinoFloris
NinoFloris / .cs
Created January 31, 2017 17:29
Controller action example
public class UsersController
{
[HttpGet]
public Task<IEnumerable<Many.Model>> GetMany(Many.Query query, [FromServices]IMediator mediator)
{
return mediator.SendAsync(query);
}
}
@NinoFloris
NinoFloris / .sh
Created December 19, 2016 19:34
Working sed loop command, old files are .bak
for i in *; do sed -i.bak 's/listen 443 ssl;/listen 443 ssl http2;/g' "$i"; done
@NinoFloris
NinoFloris / .cs
Created December 9, 2016 18:16
Mediator pipeline proof of concept
public delegate Task<TResponse> RequestHandlerDelegate<TResponse>(IAsyncRequest<TResponse> request);
public interface IRequestHandler<TRequest, TResponse> where TRequest : IAsyncRequest<TResponse>
{
Task<TResponse> Handle(TRequest message, RequestHandlerDelegate<TRequest, TResponse> next);
}
public class MediatorDecorator : IMediator
{
// [...]
@NinoFloris
NinoFloris / .cs
Created November 20, 2016 21:30
FastIntAsTextToStringBuilder
static unsafe void FastIntAsTextToStringBuilder(int input, StringBuilder sb)
{
const string sign = "-";
const int signSize = 1;
const int size = 15 + signSize;
var charbuf = stackalloc char[size];
var p = charbuf + size - 1;
var minDigits = 1;
@NinoFloris
NinoFloris / .cs
Created November 20, 2016 13:08
Automapper repro issue 1802
using System;
using AutoMapper;
namespace ConsoleApplication
{
public class Source
{
public Model Url { get; set; } = new Model();
}
@NinoFloris
NinoFloris / .cs
Created March 14, 2016 20:58
Map scalar values from Dapper rows to dto objects
public static class IEnumerableExtension {
public static IEnumerable<TFirst> Map<TFirst, TSecond, TKey>
(
this IEnumerable<TFirst> firstList,
Func<TFirst, TKey> firstKey,
Func<TSecond, TKey> secondKey,
Action<TFirst, IEnumerable<TSecond>> addChildren,
Func<IEnumerable<TSecond>> secondList
)
{