ODSP2174 · Pre-recorded
Is it still C#? Practical systems programming with .NET
Speakers: Szymon Kulec
Microsoft’s player cannot open a video at a given time: once it plays, skip to the time shown.
What the session covers
Szymon Kulec of RavenDB presents low-level .NET performance techniques drawn from building the RavenDB database in C#. He covers static virtual interface members and generic math with full JIT inlining, a ValueTask pattern with a synchronous fast path and an async slow path, and vectorizing XXHash64 with Vector256, which improved the benchmark from 419 ns to 292 ns. He also shows CPU cache prefetch, SSE2 cosine similarity for vector search and pitfalls of ref and Unsafe APIs. The session ends with RavenDB's blittable JSON format, which enables near O(1) property access without full deserialization. No product announcements are made.
Best for: C# and .NET developers building latency-sensitive services, databases or data-intensive code who want concrete benchmarked optimization patterns.
New material: no clear start of new material was found in this session.
Where to skip: Skip the intro and start at 00:59; the ValueTask fast-path pattern at 05:26 and the ref/Unsafe pitfalls at 13:26 are the most reusable parts, and the blittable JSON design at 16:11 is useful for serialization work. Nothing here relates to Copilot.
Chapters (6)
- 00:00 Recap Depth 100 · Novelty 0/3
Speaker intro: from .NET Framework 1.0 to modern C# systems programming
Szymon Kulec, Lead Developer Advocate at RavenDB, introduces the session 'Is it still C#?' on practical systems programming with .NET. He recalls .NET Framework 1.0, which had no generics, function pointers or Span, and warned against ArrayList because it boxes. He sets expectations with a humorous slide on rating distributions and polls the audience on .NET usage.
- 00:59 Deep dive Depth 400 · Novelty 1/3
Static virtual interface members: generic math, BenchmarkDotNet and full JIT inlining
The speaker explains static abstract/virtual interface members using INumberBase<TSelf> and its static One property, which int and double both implement. He shows a BenchmarkDotNet benchmark with MemoryDiagnoser and DisassemblyDiagnoser for a generic AddOne extension method. The JIT inlines everything, so the benchmark measures under a hundredth of a nanosecond with 6 bytes of code and simply returns a constant; with struct type parameters the JIT emits a specialized method. He lists the benefits as greater expressiveness for domain modelling and significant performance gains, and notes that older tricks such as default(T) for structs are no longer needed.
- 05:26 Deep dive Depth 400 · Novelty 1/3
Taming the async state machine: ValueTask sync fast path with an async slow path
Using a 'blue' (sync), 'red' (async) and 'purple' (mixed) method metaphor, the speaker shows a pattern that checks ValueTask.IsCompletedSuccessfully and returns the result synchronously, while delegating to a local static async method only on the slow path. A BenchmarkDotNet comparison of Task await versus this ValueTask approach with NoInlining shows much smaller code size, and the disassembly shows the synchronous part compiled into a compact chunk ending in a ret. The use case is RavenDB, which usually serves data from memory but sometimes has to perform disk I/O.
- 09:56 Deep dive Depth 400 · Novelty 1/3
Vectorize everything: XXHash64 with Vector256 and JIT intrinsics
The speaker walks through RavenDB's XXHash64 implementation, a non-cryptographic hash processing 32-byte blocks via four ulong accumulators with no cross-dependencies, which makes it vectorizable using the .NET Vector APIs. He shows that vector operations carry AggressiveInlining and Intrinsic attributes, so the runtime substitutes specific assembly. The benchmark improved from 419 ns to 292 ns, which he describes as about a 25% gain. He notes that vectorization suits compute-heavy work without data dependencies, while cross-lane operations incur a penalty.
- 13:26 Deep dive Depth 400 · Novelty 1/3
CPU cache prefetch, SSE2 cosine similarity and ref/Unsafe pitfalls in C#
The speaker shows that C# can prefetch the CPU cache (Sse.Prefetch0) and presents RavenDB's cosine similarity for vector search, built on SSE2 and Vector128 intrinsics. He then covers ref locals for variables, array elements (two methods) and span elements, 'in' as a read-only reference, and Unsafe APIs such as null checks, AsRef to make a read-only reference writable, and Unsafe.Add. He highlights a recurring bug: omitting 'ref' before Unsafe.Add silently updates the value instead of reassigning the reference, without a compiler warning. Refs, used in data-intensive code like RavenDB, are increasingly optimized by the .NET team so pointers are less needed.
- 16:11 Deep dive Depth 300 · Novelty 1/3
Blittable JSON in RavenDB: property-name dictionary, type tags and footer lookup
The speaker explains that with standard JSON (even System.Text.Json and source generators), accessing a property requires full deserialization or traversal, and repeated property names are duplicated. RavenDB's blittable JSON assigns numeric IDs to property names in a single pass while writing, stores type tags, and appends a property table with a footer, so lookups start from the end of the document. Benefits include near O(1) cached property access, so new indexes can be deployed without re-parsing whole documents, smaller size through dictionary compression, and memory pooling to avoid allocations. He concludes that the answer to 'is it still C#?' is yes.
Announcements (0)
No specific announcement was made in this session.
Demos (0)
No demos.