Skip to content

Instantly share code, notes, and snippets.

View sakno's full-sized avatar
🎯
Focusing

Roman Sakno sakno

🎯
Focusing
View GitHub Profile
@EgorBo
EgorBo / Dynamic PGO in .NET 6.0.md
Last active January 13, 2025 11:13
Dynamic PGO in .NET 6.0.md

Dynamic PGO in .NET 6.0

Dynamic PGO (Profile-guided optimization) is a JIT-compiler optimization technique that allows JIT to collect additional information about surroundings (aka profile) in tier0 codegen in order to rely on it later during promotion from tier0 to tier1 for hot methods to make them even more efficient.

What exactly PGO can optimize for us?

  1. Profile-driving inlining - inliner relies on PGO data and can be very aggressive for hot paths and care less about cold ones, see dotnet/runtime#52708 and dotnet/runtime#55478. A good example where it has visible effects is this StringBuilder benchmark:

  2. Guarded devirtualization - most monomorphic virtual/interface calls can be devirtualized using PGO data, e.g.:

void DisposeMe(IDisposable d)
@Horusiath
Horusiath / Hyparview.fs
Last active January 31, 2025 12:59
HyParView: a membership protocol for reliable gossip-based broadcast
// Reference: https://asc.di.fct.unl.pt/~jleitao/pdf/dsn07-leitao.pdf
module Protocols.Hyparview
open System
open System.Runtime.ExceptionServices
open System.Threading
type Endpoint = string
type TTL = int
@AArnott
AArnott / Cancellation.cs
Last active October 16, 2024 17:10
Graceful console app cancellation on Ctrl+C
class Program
{
static async Task Main(string[] args)
{
// Add this to your C# console app's Main method to give yourself
// a CancellationToken that is canceled when the user hits Ctrl+C.
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
Console.WriteLine("Canceling...");