binary serializer for C# and Unity. AlterNats ★271 An alternative high performance NATS client for .NET. MessagePipe ★1062 High performance in-memory/distributed messaging pipeline for .NET and Unity. Ulid ★629 Fast .NET C# Implementation of ULID for .NET and Unity. MessagePack ★4836 Extremely Fast MessagePack Serializer for C#(.NET, Unity). MagicOnion ★3308 Unified Realtime/API framework for .NET platform and Unity. UniTask ★5901 Provides an efficient allocation free async/await integration for Unity. ZString ★1524 Zero Allocation StringBuilder for .NET and Unity.
binary serializer for C# and Unity. AlterNats ★271 An alternative high performance NATS client for .NET. MessagePipe ★1062 High performance in-memory/distributed messaging pipeline for .NET and Unity. Ulid ★629 Fast .NET C# Implementation of ULID for .NET and Unity. MessagePack ★4836 Extremely Fast MessagePack Serializer for C#(.NET, Unity). MagicOnion ★3308 Unified Realtime/API framework for .NET platform and Unity. UniTask ★5901 Provides an efficient allocation free async/await integration for Unity. ZString ★1524 Zero Allocation StringBuilder for .NET and Unity. 様々なジャンルで、競合の追随を許さないハイパフォー マンスを追求したライブラリを公開してきました。 このセッションではそれらの経験を元に、現代のC#で最 高のパフォーマンスを叩き出す技術を紹介します。
// Write value as BigEndian var temp = BinaryPrimitives.ReverseEndianness((ushort)value); Unsafe.WriteUnaligned(ref dest[1], temp); Utf8Formatter.TryFormat(value, dest, out var bytesWritten); JSONはstringではなくてUTF8のバイナリと して直接読み書きすることで高速化する MessagePackの仕様に従って先頭に型識別子と、 値をBigEndianで書き込む
// Write value as BigEndian var temp = BinaryPrimitives.ReverseEndianness((ushort)value); Unsafe.WriteUnaligned(ref dest[1], temp); Utf8Formatter.TryFormat(value, dest, out var bytesWritten); JSONはstringではなくてUTF8のバイナリと して直接読み書きすることで高速化する MessagePackの仕様に従って先頭に型識別子と、 値をBigEndianで書き込む MessagePack for C#は確かに速い。しかしMessagePack としてのバイナリ仕様の都合上、なにをどうやっても 「理想的な最速コード」よりも遅くなる……
// INFO { } internal static class ServerOpCodes { public const int Info = 1330007625; // "INFO" public const int Msg = 541545293; // "MSG " public const int Ping = 1196312912; // "PING" public const int Pong = 1196314448; // "PONG" public const int Ok = 223039275; // "+OK¥r" public const int Error = 1381123373; // "-ERR" } 後続(スペースや¥r)と合わせると、ちょうど NATSのOpCodeは全て4バイト(int)で判定可能な ので、事前にint化した定数郡を作っておく ReadOnlySpan<byte>から直接int化 文字列化して比較は論外ですが、せっかく4バ イトでいけるのでint化した比較が一番速い NOTE: まぁバイナリプロトコルで先頭1バイトが種類を表してる、みたい なのが一番いいんですけどね……。テキストプロトコルよくない。