Skip to content

Instantly share code, notes, and snippets.

package main
import (
"encoding/json"
"flag"
"errors"
"fmt"
"github.com/alexanderkyte/pcap"
"io/ioutil"
"log"
@alexanderkyte
alexanderkyte / Number of objects inflated and disposed x total active memory (Leaks)
Created June 26, 2019 19:01
GraphViz XySeries csv (actual graphviz invokes coming)
2.000000, 12.582912
3.000000, 51.375328
5.000000, 7.337984
2.000000, 1.050624
7.000000, 37.748736
3.000000, 16.775168
3.000000, 3.147776
2.000000, 1.046528
1.000000, 0.000000
2.000000, 0.000000
@alexanderkyte
alexanderkyte / CRASH_REPORT_FOSSY
Created June 11, 2019 19:42
Cross platform crash reporting JSON format (ran through https://jsonlint.com/ for formatting)
{
"protocol_version": "0.0.4",
"configuration": {
"version": "(6.5.0) (llvm_disable_direct/d325be63b32)",
"tlc": "normal",
"sigsgev": "altstack",
"notifications": "kqueue",
"architecture": "amd64",
"disabled_features": "none",
"smallconfig": "disabled",
Sample JSON: https://gist.github.com/alexanderkyte/905ad38e9fd51e887a01855de86190af
Contacts: Lee Culver, abraham.ronel@microsoft.com (MERP.app / Office)
Code:
Managed side: https://github.com/mono/mono/blob/470354fa817716739615ff0c6cfefca42ec8b385/mcs/class/corlib/Mono/Runtime.cs#L142
Unmanaged side:
Icalls: https://github.com/mono/mono/blob/c398e19d3515c6bbb6046ed014b2095594a15229/mono/metadata/icall.c#L6197
Cross-platform printing: https://github.com/mono/mono/blob/0e65799c8ec6982621d18aef8f1475184f4c99a3/mono/utils/mono-state.c
MS-internal printing/MERP.app invoking: https://github.com/mono/mono/blob/0e65799c8ec6982621d18aef8f1475184f4c99a3/mono/utils/mono-merp.c
{
"protocol_version": "0.0.4",
"configuration": {
"version": "(6.5.0) (android_crash_cleanup/21a2081)",
"tlc": "__thread",
"sigsgev": "altstack",
"notifications": "epoll",
"architecture": "amd64",
"disabled_features": "none",
"smallconfig": "disabled",

LLVM Is Magic

Teaching Mono to use LLVM better

The performance of modern software can be bewildering. Tiny bits of plastic and wire routinely astound, outperforming the supercomputers of yesteryear. Far from a rarity, our systems make such a feat the default. We trust things to be fast, considering almost any delay a fault. We are all told about the evils of premature optimization.

This performance largely comes from leveraging a small number of important optimizations. When people hear about “parallelism” in the context of computer hardware, they think about multithreaded programs running on multicore multiprocessors. The performance of code that isn’t so “multi” relies just as much on parallelism. When a processor runs sequential user code, operations that don’t depend on each other will run at the same time.

In order to avoid having unused hardware idling while drawing power, code has to be reordered. There always must be enough work to do in parallel, or performance drops very quickly. The rea

define monocc i32 @"System.SpanHelpers:IndexOf (byte&,byte,int)"(i64* %arg_searchSpace, i32 %arg_value, i32 %arg_length) #0 {
BB0:
%0 = alloca <16 x i8>, align 16
%1 = alloca <2 x i64>, align 16
%2 = alloca <16 x i8>, align 16
%3 = alloca i64, align 8
%4 = load volatile i64, i64* inttoptr (i64 4497641040 to i64*)
%5 = icmp eq i64 %4, 0
%6 = call i1 @llvm.expect.i1(i1 %5, i1 true)
%7 = alloca <16 x i8>, align 16
Mono Ahead of Time compiler - compiling assembly /Users/akyte/Projects/SpanCrash/SpanCrash/bin/Debug/SpanCrash.exe
AOTID 71A837F8-2414-E5AB-71ED-B6C8B8693C53
converting llvm method int SpanCrash.MainClass:SpanIndexOfInner (System.Span`1<byte>)
created temp 0 (R16) of type System.Int32
creating vars
created temp 1 (R17) of type System.Span<System.Byte>
return : arg R16 <-
arg [0]: arg R17 <-
creating locals
local [0]: created temp 2 (R18) of type System.Byte
akyte@Alexanders-MacBook-Pro-3 ~/Projects/NoThrowInline/NoThrowInline/bin/Release (master*) $ MONO_EXECUTABLE="/Users/akyte/perf_mono/mono/mono/mini/mono-sgen --" MONO_PATH=/Users/akyte/perf_mono/mono/mcs/class/lib/net_4_x /Users/akyte/perf_mono/mono/runtime/mono-wrapper --aot-path=/Users/akyte/perf_mono/mono/mcs/class/lib/net_4_x /Users/akyte/linker/test/Mono.Linker.Tests/bin/Debug/monolinker.exe --annotate-unseen-callers -a NoThrowInline.exe
akyte@Alexanders-MacBook-Pro-3 ~/Projects/NoThrowInline/NoThrowInline/bin/Release (master*) $ mv output/NoThrowInline.exe NoThrowInlineFoo.exe
akyte@Alexanders-MacBook-Pro-3 ~/Projects/NoThrowInline/NoThrowInline/bin/Release (master*) $ monodis --customattr output/NoThrowInline.exe
Custom Attributes Table (1..14)
1: MethodDef: 1: instance void class [mscorlib]System.Runtime.CompilerServices.ReflectionBlockedAttribute::'.ctor'() []
2: Assembly: 1: instance void class [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::'.ctor'(int32) [8]
3: Assemb
akyte@Alexanders-MacBook-Pro-3 ~/perf_mono/mono/mono (nonnull_attr_merge*) $ git grep -i NoOptimization | cat
dis/get.c: { METHOD_IMPL_ATTRIBUTE_NOOPTIMIZATION, "nooptimization " },
metadata/attrdefs.h: MONO_METHOD_IMPL_ATTR_NOOPTIMIZATION = 0x0040,
metadata/tabledefs.h:#define METHOD_IMPL_ATTRIBUTE_NOOPTIMIZATION 0x0040
tests/tailcall/coreclr/JIT/opt/Tailcall/TailcallVerifyTransparentLibraryWithPrefix.il: .method public hidebysig static int32 Test1() cil managed nooptimization
tests/tailcall/coreclr/JIT/opt/Tailcall/TailcallVerifyTransparentLibraryWithPrefix.il: .method public hidebysig static int32 Test2() cil managed nooptimization
tests/tailcall/coreclr/JIT/opt/Tailcall/TailcallVerifyTransparentLibraryWithPrefix.il: .method public hidebysig static int32 Test3() cil managed nooptimization
tests/tailcall/coreclr/JIT/opt/Tailcall/TailcallVerifyTransparentLibraryWithPrefix.il: .method public hidebysig static int32 Test4() cil managed nooptimization
tests/tailcall/coreclr/JIT/opt/Tailcall