Skip to content

Instantly share code, notes, and snippets.

View ahsonkhan's full-sized avatar
💭
Working to empower every developer on the planet to achieve more.

Ahson Khan ahsonkhan

💭
Working to empower every developer on the planet to achieve more.
  • Microsoft
View GitHub Profile
@ahsonkhan
ahsonkhan / SpanSliceIndexOf.md
Last active March 11, 2017 02:12
Comparing Span Slice then IndexOf vs using an IndexOf overload that takes index and count

Here are the latest results and conclusion.

Essentially, for Span specifically, calling Slice then IndexOf is just as good (if not better) than calling the IndexOf overload which removes the need to Slice.

dotnet/corefxlab#1278

(I am limiting the discussion to fast span since the conclusion doesn’t generally change for slow span)

image

@ahsonkhan
ahsonkhan / job-testLinux-16-console.txt
Created May 9, 2017 22:06
job-testLinux-16-console.txt
Started by user Ahson Khan
Building in workspace C:\Program Files (x86)\Jenkins\workspace\testLinux
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://github.com/dotnet/dotnet-ci # timeout=10
Fetching upstream changes from https://github.com/dotnet/dotnet-ci
> git.exe --version # timeout=10
> git.exe fetch --tags --progress https://github.com/dotnet/dotnet-ci +refs/heads/*:refs/remotes/origin/* # timeout=30
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
@ahsonkhan
ahsonkhan / System.Text.Primitives.md
Last active June 19, 2017 01:37
System.Text.Primitives API Review
namespace System.Buffers.Text {
    public static class Base64 {
        public static int ComputeDecodedLength(ReadOnlySpan<byte> source);
        public static int ComputeEncodedLength(int sourceLength);
        public static TransformationStatus Decode(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten);
        public static TransformationStatus DecodeInPlace(Span<byte> buffer, out int bytesConsumed, out int bytesWritten);
        public static TransformationStatus Encode(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten);
        public static TransformationStatus EncodeInPlace(Span<byte> buffer, int sourceLength, out int bytesWritten);
    }
@ahsonkhan
ahsonkhan / IntParserUnrolled.md
Last active June 24, 2017 04:23
Loop unrolled int 32 parser
public static bool TryParseInt32(ReadOnlySpan<byte> text, out int value, out int bytesConsumed)
{
    int textLength = text.Length;
    if (textLength < 1) goto FalseExit;

    int sign = 1;
    int index = default;
    int num = text[index];
@ahsonkhan
ahsonkhan / JsonReaderPerf-report-github.md
Last active May 12, 2018 00:51
JsonLab and Json.NET JsonReader Performance Comparison Results for various JSON strings (UTF-8 and UTF-16)
BenchmarkDotNet=v0.10.14.534-nightly, OS=Windows 10.0.16299.371 (1709/FallCreatorsUpdate/Redstone3)
Intel Xeon CPU E5-1620 v2 3.70GHz, 1 CPU, 8 logical and 4 physical cores
Frequency=3604598 Hz, Resolution=277.4234 ns, Timer=TSC
.NET Core SDK=2.1.300-rtm-008823
  [Host]     : .NET Core 2.1.0-rtm-26508-02 (CoreCLR 4.6.26508.04, CoreFX 4.6.26508.03), 64bit RyuJIT
  Job-JIQQBR : .NET Core 2.1.0-rtm-26508-02 (CoreCLR 4.6.26508.04, CoreFX 4.6.26508.03), 64bit RyuJIT

InvocationCount=1024 TargetCount=5 WarmupCount=3 
@ahsonkhan
ahsonkhan / ArrayBufferWriter.cs
Created January 28, 2019 08:10
Sample implementation of ArrayBufferWriter, a class that implements IBufferWriter<byte>
namespace System.Buffers
{
public class ArrayBufferWriter : IBufferWriter<byte>, IDisposable
{
private byte[] _rentedBuffer;
private int _written;
private long _committed;
private const int MinimumBufferSize = 256;
@ahsonkhan
ahsonkhan / ArrayBufferWriter.ArrayPool.cs
Created January 29, 2019 01:11
Sample implementation of ArrayBufferWriter, a class that implements IBufferWriter<byte> backed by ArrayPool<byte>.Shared.
public class ArrayBufferWriter : IBufferWriter<byte>, IDisposable
{
private byte[] _rentedBuffer;
private int _written;
private long _committed;
private const int MinimumBufferSize = 256;
public ArrayBufferWriter(int initialCapacity = MinimumBufferSize)
{
@ahsonkhan
ahsonkhan / ref-api-diff.md
Last active February 22, 2019 08:44
Difference in reference assemblies between .NET Core 3.0 master and .NET Core 3.0 UpdateRefs branch
@ahsonkhan
ahsonkhan / CallStack-StackOverflow.txt
Created February 27, 2019 01:47
ApiCompat write diff stack overflow for uap
[External Code]
> Microsoft.Cci.Extensions.dll!Microsoft.Cci.Writers.CSharp.CSDeclarationWriter.WriteEnumValue(Microsoft.Cci.IMetadataConstant constant, Microsoft.Cci.ITypeReference constantType) Line 67 C#
Microsoft.Cci.Extensions.dll!Microsoft.Cci.Writers.CSharp.CSDeclarationWriter.WriteMetadataConstant(Microsoft.Cci.IMetadataConstant constant, Microsoft.Cci.ITypeReference constantType) Line 258 C#
Microsoft.Cci.Extensions.dll!Microsoft.Cci.Writers.CSharp.CSDeclarationWriter.WriteEnumValue(Microsoft.Cci.IMetadataConstant constant, Microsoft.Cci.ITypeReference constantType) Line 123 C#
Microsoft.Cci.Extensions.dll!Microsoft.Cci.Writers.CSharp.CSDeclarationWriter.WriteMetadataConstant(Microsoft.Cci.IMetadataConstant constant, Microsoft.Cci.ITypeReference constantType) Line 258 C#
Microsoft.Cci.Extensions.dll!Microsoft.Cci.Writers.CSharp.CSDeclarationWriter.WriteEnumValue(Microsoft.Cci.IMetadataConstant constant, Microsoft.Cci.ITypeReference constantType) Line 123 C#
Microsoft.Cci.Extensions.dll!M
@ahsonkhan
ahsonkhan / Class_Utf8JsonWriter.md
Created April 17, 2019 12:07
Utf8JsonWriter Re-design based on usability and reliability feedback

Motivation - Usability and Reliability:

  • The current writer is a ref struct, which requires passing by ref.
  • The use of array pool could result in reliability concerns if misused.
  • Async writes and state passing could be problematic.
  • No IBufferWriter implementation built in.

Goals:

  • Continue to support IBufferWriter (i.e. PipeWriter) directly
  • Keep ability for user to control buffering with ability to avoid data copies.