(# Modern C# Mastery — .NET 10 High-Performance Fraud Engine Labs)
A collection of focused labs that demonstrate high-performance patterns in modern C# and .NET 10, built around a small fraud-detection engine. Each lab is a self-contained experiment showcasing techniques such as zero-allocation parsing, SIMD/vectorization, lock-free data structures, zero-copy binary parsing, high-throughput pipelines, and distributed messaging patterns.
- Small, focused labs exercised from a single launcher in MemoryPerformanceLab/Program.cs.
- Zero-heap JSON parsing using
Utf8JsonReaderandReadOnlySpan<byte>. - SIMD-accelerated scanning via
Vector128<T>(VectorizedDetector). - Lock-free Bloom filter deduplication using
XxHash3and atomic operations (LockFreeBloomFilter). - Unsafe, zero-copy binary parsing with
MemoryMarshalandUnsafe(UnsafeBinaryParser). - High-throughput producer/consumer pipelines using
System.Threading.Channels(FraudProcessingPipeline). - Simple distributed patterns: transactional outbox and simulated gRPC streaming (
DistributedOutbox,GrpcFraudStreamService).
- .NET 10 SDK (target framework:
net10.0).
From the repository root:
dotnet build MemoryPerformanceLab/MemoryPerformanceLab.csproj -c ReleaseRun the interactive launcher which presents the available labs:
dotnet run --project MemoryPerformanceLab/MemoryPerformanceLab.csprojThe console app displays a numbered menu. Choose a lab to run (for example, 1 for zero-allocation UTF-8 parsing).
The main launcher enumerates these experiments (see MemoryPerformanceLab/Program.cs):
Zero-Allocation UTF-8 Parsing— Parse JSON directly from UTF-8 spans with zero heap allocations (Utf8TransactionParser).SIMD Vectorized Batch Duplicate Scan— Use hardware vector intrinsics to scan arrays in parallel (VectorizedDetector).High-Throughput Concurrent Pipeline— Producer/consumer channels withValueTaskworkers (FraudProcessingPipeline).Memory Allocation Profiling— Compare allocation characteristics of different parsers/serializers.Compile-Time Fast Validation— Generated/fast validation patterns.Live Fraud Alert Streaming— Server-Sent Events / IAsyncEnumerable streaming example.Resilient External Risk API Calls— Retry and backoff strategies for external calls.Unsafe Zero-Copy Binary Field Parsing— Read binary payloads without copies usingUnsafe(UnsafeBinaryParser).Lock-Free Bloom Filter Deduplication— Fast, concurrent deduplication using atomic bit ops (LockFreeBloomFilter).Native AOT & Zero-JIT Inspection— Native AOT related checks.Distributed gRPC Network Stream Processing— Simulated inbound gRPC stream handling (GrpcFraudStreamService).Transactional Outbox Pattern— Enqueue and dispatch reliably to a broker (DistributedOutbox).Post-Quantum Tokenized Settlement— Stack-allocated PQC HMAC example.
- Launcher: MemoryPerformanceLab/Program.cs
- Project file: MemoryPerformanceLab/MemoryPerformanceLab.csproj
- Services: MemoryPerformanceLab/Services
- The code is intentionally small and educational — focus is on demonstrating micro-optimizations and concurrency patterns rather than production-ready glue code.
- Many examples use low-level APIs (
Unsafe,MemoryMarshal, intrinsics) to illustrate trade-offs; treat these as learning artifacts and verify safety for production use.
- Run individual labs and profile with the dotnet-trace / dotnet-dump tools to see allocations and hotspots.
- Add unit tests that validate parsing correctness and pipeline behavior under concurrency.
- Expand README with per-lab guidance, inputs, and expected outputs if you want reproducible experiments.
Contributions and improvements are welcome. Open an issue or PR describing the change and which lab it affects.
Generated README based on the launcher and service implementations in MemoryPerformanceLab.