Skip to content

Instantly share code, notes, and snippets.

@dadhi
dadhi / fastest_way_to_emit_ctor_call_eg_opcodes_newobj.cs
Created Jul 26, 2022
Optimize ILGenerator.Emit(OpCodes.Newobj, ctor)
View fastest_way_to_emit_ctor_call_eg_opcodes_newobj.cs
using System;
using System.Reflection.Emit;
using System.Diagnostics;
public class Program
{
public static void Main()
{
var con = typeof(B<int>).GetConstructors()[0];
@dadhi
dadhi / playground.rs
Last active Jul 20, 2022 — forked from rust-play/playground.rs
MaybeUninit and type_name implemented as AnyExt
View playground.rs
#![allow(unused)]
fn main() {
use std::mem::{self, MaybeUninit};
let data = {
// Create an uninitialized array of `MaybeUninit`. The `assume_init` is
// safe because the type we are claiming to have initialized here is a
// bunch of `MaybeUninit`s, which do not require initialization.
let mut data: [MaybeUninit<Vec<u32>>; 1000] = unsafe {
MaybeUninit::uninit().assume_init()
@dadhi
dadhi / code.cs
Created Jul 16, 2022 — forked from hypeartist/code.cs
Type instantiation (.ctor with parameters)
View code.cs
object obj;
var r = 0;
const int cnt = 1000000;
var constructorInfo = typeof(Class).GetConstructor(new[] { typeof(int) })!;
var hCtor = constructorInfo.MethodHandle;
RuntimeHelpers.PrepareMethod(RuntimeMethodHandle.FromIntPtr(hCtor.Value));
var pCtor = (delegate* managed<object, int, void>)hCtor.GetFunctionPointer();
View Quic.cs
using System.IO.Pipelines;
using System.Net;
using System.Net.Security;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
var builder = WebApplication.CreateBuilder(args);
View Graph-tree-with-mermaid.md
graph TB
    A((1, 2))-->B((2))
    A-->C((3))
    A-->D((4))
    B-->E((5))
    B-->F((6))
    B-->G((7))
    C-->H((8))
 D--&gt;I((9))
@dadhi
dadhi / SpecializedFactoryExample.worksheet.sc
Last active Feb 23, 2022
Specialized factory type class in Scala
View SpecializedFactoryExample.worksheet.sc
//live: https://scastie.scala-lang.org/dadhi/G2uzgCqXSbiav34bM602iw/68
trait EntryFactory[K] {
def create(key: K): Entry[K]
}
object EntryFactory {
implicit def anyFactory[K]: EntryFactory[K] =
new EntryFactory[K] {
override def create(key: K) = KEntry(key, key.hashCode)
@dadhi
dadhi / MinimalAPIs.md
Created Sep 11, 2021 — forked from davidfowl/MinimalAPIs.md
Minimal APIs at a glance
View MinimalAPIs.md

Minimal APIs

WebApplication

Creating an application

var app = WebApplication.Create(args);

app.MapGet("/", () =&gt; "Hello World");
@dadhi
dadhi / latency.txt
Created Apr 14, 2021 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@dadhi
dadhi / PackRef.md
Created Nov 23, 2020
Control PackageReference
View PackRef.md

NuGet/Home#5986 (comment)

I've found that you can manually control which .dlls to reference and which .dlls to copy to output from a NuGet package if you turn off all assets on the PackageReference:

<PackageReference Include="Foo.MyPackage" Version="1.0.0" ExcludeAssets="all" GeneratePathProperty="true" />

and then manually reference the .dlls you need: