This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// A helper to await for events in an asynchronous manner. | |
/// </summary> | |
public static class EventAwaiter | |
{ | |
/// <summary> | |
/// Awaits a specific event to be raised and executes a callback when that happens. | |
/// </summary> | |
/// <typeparam name="THandler">The type of handler to await.</typeparam> | |
/// <param name="register">An <see cref="Action{T}"/> to register the event.</param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Diagnostics.Contracts; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
#nullable enable | |
namespace Profiling | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows.Input; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Microsoft.Xaml.Interactivity; | |
#nullable enable | |
namespace Microsoft.Xaml.Interactions.Core | |
{ | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
namespace System | |
{ | |
/// <summary> | |
/// A <see langword="ref"/> <see langword="struct"/> that enumerates the items in a given <see cref="ReadOnlySpan{T}"/> instance | |
/// </summary> | |
/// <typeparam name="T">The type of items to enumerate</typeparam> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics.Contracts; | |
using System.Runtime.CompilerServices; | |
namespace System | |
{ | |
/// <summary> | |
/// A <see langword="class"/> with some extension methods for the <see cref="ReadOnlySpan{T}"/> type | |
/// </summary> | |
public static class ReadOnlySpanExtensions | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Buffers; | |
using System.Diagnostics.Contracts; | |
using System.Runtime.CompilerServices; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace MaxBenchmark | |
{ | |
class Program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Method | Mean | Error | StdDev | Ratio | | |
|------------------------ |------------:|-----------:|-----------:|------:| | |
| ReflectionSmall | 954.36 ms | 11.8428 ms | 11.0778 ms | 1.00 | | |
| ILGetterSmall | 678.82 ms | 4.5664 ms | 3.8132 ms | 0.71 | | |
| UnwrappedILGetterSmall | 661.00 ms | 5.2797 ms | 4.6803 ms | 0.69 | | |
| SingleILGetterSmall | 65.24 ms | 0.3079 ms | 0.2880 ms | 0.07 | | |
| | | | | | | |
| ReflectionMedium | 1,427.80 ms | 9.2508 ms | 8.6532 ms | 1.00 | | |
| ILGetterMedium | 1,023.99 ms | 6.6233 ms | 6.1954 ms | 0.72 | | |
| UnwrappedILGetterMedium | 1,011.03 ms | 2.6657 ms | 2.3631 ms | 0.71 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe (object[] References, byte[] Bytes) GetData( | |
Delegate instance, DataLoader loader, | |
int referenceCount, int byteSize) | |
{ | |
// Reference and byte array | |
object[] refs = ArrayPool<object>.Shared.Rent(referenceCount); | |
byte[] bytes = ArrayPool<byte>.Shared.Rent(byteSize); | |
ref object r0 = ref refs.Length > 0 ? ref refs[0] : ref Unsafe.AsRef<object>(null); | |
ref byte r1 = ref bytes.Length > 0 ? ref bytes[0] : ref Unsafe.AsRef<byte>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom delegate that takes the two ref parameters we need | |
public delegate void DataLoader(object instance, ref object r0, ref byte r1); | |
/* The method that takes a delegate and the list of discovered | |
* fields for the closure type and its nested closure types, | |
* and builds our dynamic IL method that loads all the fields sequentially */ | |
public static DataLoader BuildDataLoader( | |
Delegate instance | |
IReadOnlyList<ClosureField> fields) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void EmitStoreToAddress(this ILGenerator il, Type type) | |
{ | |
if (type.IsValueType) | |
{ | |
// Pick the optimal opcode to set a value type | |
OpCode opcode = Marshal.SizeOf(type) switch | |
{ | |
// Use the faster op codes for sizes <= 8 | |
1 when type == typeof(byte) || type == typeof(sbyte) => OpCodes.Stind_I1, | |
2 when type == typeof(short) || type == typeof(ushort) => OpCodes.Stind_I2, |
NewerOlder