.NET8 Deep Dive
Udaiappa Ramachandran ( Udai )
https://udai.io
About me
• Udaiappa Ramachandran ( Udai )
• CTO-Akumina, Inc.
• Microsoft Azure MVP
• Cloud Expert
• Microsoft Azure, Amazon Web Services, and Google
• New Hampshire Cloud User Group (http://www.meetup.com/nashuaug )
• https://udai.io
Agenda
• .NET 8
• Primary Constructor
• Garbage Collector
• JSON Serialization
• Fast Search
• Dynamic PGO
• Time Abstraction
• Cryptography
• Comprssion - ZipFile
• FrozenSet
• RegEx Code Generation
• Native AOT
• Redis Output Caching
• Background Worker
• Semantic Kernel
.NET 8 Downloads
https://dotnet.microsoft.com/en-us/download/dotnet/8.0
SearchValues
• Fastest way of searching any set of bytes or chars
• As per document: It is widely used asp.net libraries
• SearchValues<char> Values2 = SearchValues.Create("AnyStringPattern
ex.,ABab01");
Dynamic PGO (Profile Guided Optimization)
• Tiered Compilation
• JIT recompiles methods, compile once and optimize it based on how many times method used
• $env:DOTNET_JitDisasmSummary=1
• Del env:DOTNET_JitDisasmSummary
• $env:DOTNET_JitDisasm="IsEmpty"
JsonUnmappedMemberHandling
• Mark all data members available in the JSON payload
• [JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Disallow)]
Time Abstraction
• System.TimeProvider
• System.Threading.ITimer
Comperssion
• Stream compression saves disk space by eliminating the need to store files
before compressing them. This allows direct memory management of the
results, making it useful when storage space is limited.
• Several overloads
• ZipFile.CreateFromDirectory(@"C:TempSample",
@"C:TempSampleSample.zip")
RegEx source gen
• Must be a partial class
• Attributed by GeneratedRegex
FrozenSet
• FrozenSet<T>
• List<T>.AddRanage(Ienumerable<T>)
• Int32.ToString()
Cryptography
• SHA3
• GetItems
System.Text.Json
• Native AOT – functional and size reduction
• ASP.NET Core Interop – Easier to register source generator, size reduction
• Bugfixes and reliability – issues related to reflection
• <JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflect
ionEnabledByDefault>
ASP.NET Core 8
• Server improvements – Kestrel
• Header parsing
• One of the first thing processed by a server
• Removed allocations, optimization using sequencereader
• HTTP.sys
• Removed extra thread pool dispatching 15% gain in JSON end to end benchmark
• Kernel-mode response buffering-
• OS can optimize sending the data by parallelizing writes and/or sending largest chunks of data at a time
• benefits when using connections with high latency
• Removed GC handles in response writing
• reduced it with native code (NativeMemory.Alloc/Free)
• reduces pinning and fragmentation
• Improved perf of request headers
• removed LINQ from httpcontext.request.headers.keys and .Count that means count is now allocation free!
RedisCaching
DI Change
• KeyedService
BackgroundWorker
• BackgroundService
• HostedService
• HostedLifeCylceService
Native AOT (Ahead-Of-Time Compilation)
• Faster startup time
• Smaller file size
• Smaller memory footprint on computer
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/native-aot?view=aspnetcore-8.0
Request Delegate Generator (RDG)
• Compile time source generator
• Minimal APIs are NOT Trimmer and native AOT friendly
• Turns each Map method (MapGet,MapPost,MapPatch,MapPut and MapDelete)
into a RequestDelegate associated with the specific route
• Is enabled automatically in projects when publishing with native AOT is enabled.
• Can be manually enabled even when not using native AOT by setting
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator> in
the project file:
• When manually enabled
• Evaluating a project's compatibility with native AOT.
• To reduce the app's startup time by pregenerating the request delegates.
Performance - MAUI
• Android Startup
• iOS App Size
• NativeAOT on iOS (faster startup time and smaller memory footprints)
• Memory Leaks on Apple Platform (Roslyn analyzer for iOS circular reference)
(https://aka.ms/maui-memory-leaks)
• Android: Improvements in Java interop(managing javaobject and heap object, now
it is pinvoke into java string and reduce the allocation), asking label or text
• Dotnet-trace, dotnet-gcdump
• Dotnet-dsrouter android|android-emu|ios|ios-sim (aka.ms/profile-maui)
https://devblogs.microsoft.com/dotnet/dotnet-8-performance-improvements-in-dotnet-maui/
Something to build using Semantic Kernel
• Content Creation and Editing
• Current: we have some form of OpenAPI integration(request/response of text input and text or
image being output)
• Proposed: replace with Semantic Kernel to create or edit content using interactive mode and
language translation.
• AI powered analytics
• Smart content creation using prompts which includes creating content, creating
Akumina workflow, etc.,
• FrontEnd: AI powered widgets, conversational based content experience. Let the
conversation drive the experience for employee productivity
https://github.com/microsoft/semantic-kernel
https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main
https://learn.microsoft.com/en-us/semantic-kernel/
Reference
• What’s new in .NET8: https://learn.microsoft.com/en-us/dotnet/core/whats-
new/dotnet-8
• Performance Improvements ASP.NET Core:
https://devblogs.microsoft.com/dotnet/performance-improvements-in-aspnet-core-8/
• Performance Improvements MAUI : https://devblogs.microsoft.com/dotnet/dotnet-8-
performance-improvements-in-dotnet-maui/
• RoadMap: https://themesof.net/roadmap?product=.NET&release=8.0
• C#12: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12
• F#8: https://devblogs.microsoft.com/dotnet/announcing-fsharp-8
• Benchmarks: https://aka.ms/aspnet/benchmarks
• Demo Samples: https://github.com/nhcloud/techtalk

DOTNET8.pptx

  • 1.
    .NET8 Deep Dive UdaiappaRamachandran ( Udai ) https://udai.io
  • 2.
    About me • UdaiappaRamachandran ( Udai ) • CTO-Akumina, Inc. • Microsoft Azure MVP • Cloud Expert • Microsoft Azure, Amazon Web Services, and Google • New Hampshire Cloud User Group (http://www.meetup.com/nashuaug ) • https://udai.io
  • 3.
    Agenda • .NET 8 •Primary Constructor • Garbage Collector • JSON Serialization • Fast Search • Dynamic PGO • Time Abstraction • Cryptography • Comprssion - ZipFile • FrozenSet • RegEx Code Generation • Native AOT • Redis Output Caching • Background Worker • Semantic Kernel
  • 4.
  • 5.
    SearchValues • Fastest wayof searching any set of bytes or chars • As per document: It is widely used asp.net libraries • SearchValues<char> Values2 = SearchValues.Create("AnyStringPattern ex.,ABab01");
  • 6.
    Dynamic PGO (ProfileGuided Optimization) • Tiered Compilation • JIT recompiles methods, compile once and optimize it based on how many times method used • $env:DOTNET_JitDisasmSummary=1 • Del env:DOTNET_JitDisasmSummary • $env:DOTNET_JitDisasm="IsEmpty"
  • 7.
    JsonUnmappedMemberHandling • Mark alldata members available in the JSON payload • [JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Disallow)]
  • 8.
  • 9.
    Comperssion • Stream compressionsaves disk space by eliminating the need to store files before compressing them. This allows direct memory management of the results, making it useful when storage space is limited. • Several overloads • ZipFile.CreateFromDirectory(@"C:TempSample", @"C:TempSampleSample.zip")
  • 10.
    RegEx source gen •Must be a partial class • Attributed by GeneratedRegex
  • 11.
  • 12.
  • 13.
    System.Text.Json • Native AOT– functional and size reduction • ASP.NET Core Interop – Easier to register source generator, size reduction • Bugfixes and reliability – issues related to reflection • <JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflect ionEnabledByDefault>
  • 14.
    ASP.NET Core 8 •Server improvements – Kestrel • Header parsing • One of the first thing processed by a server • Removed allocations, optimization using sequencereader • HTTP.sys • Removed extra thread pool dispatching 15% gain in JSON end to end benchmark • Kernel-mode response buffering- • OS can optimize sending the data by parallelizing writes and/or sending largest chunks of data at a time • benefits when using connections with high latency • Removed GC handles in response writing • reduced it with native code (NativeMemory.Alloc/Free) • reduces pinning and fragmentation • Improved perf of request headers • removed LINQ from httpcontext.request.headers.keys and .Count that means count is now allocation free!
  • 15.
  • 16.
  • 17.
  • 18.
    Native AOT (Ahead-Of-TimeCompilation) • Faster startup time • Smaller file size • Smaller memory footprint on computer https://learn.microsoft.com/en-us/aspnet/core/fundamentals/native-aot?view=aspnetcore-8.0
  • 19.
    Request Delegate Generator(RDG) • Compile time source generator • Minimal APIs are NOT Trimmer and native AOT friendly • Turns each Map method (MapGet,MapPost,MapPatch,MapPut and MapDelete) into a RequestDelegate associated with the specific route • Is enabled automatically in projects when publishing with native AOT is enabled. • Can be manually enabled even when not using native AOT by setting <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator> in the project file: • When manually enabled • Evaluating a project's compatibility with native AOT. • To reduce the app's startup time by pregenerating the request delegates.
  • 20.
    Performance - MAUI •Android Startup • iOS App Size • NativeAOT on iOS (faster startup time and smaller memory footprints) • Memory Leaks on Apple Platform (Roslyn analyzer for iOS circular reference) (https://aka.ms/maui-memory-leaks) • Android: Improvements in Java interop(managing javaobject and heap object, now it is pinvoke into java string and reduce the allocation), asking label or text • Dotnet-trace, dotnet-gcdump • Dotnet-dsrouter android|android-emu|ios|ios-sim (aka.ms/profile-maui) https://devblogs.microsoft.com/dotnet/dotnet-8-performance-improvements-in-dotnet-maui/
  • 21.
    Something to buildusing Semantic Kernel • Content Creation and Editing • Current: we have some form of OpenAPI integration(request/response of text input and text or image being output) • Proposed: replace with Semantic Kernel to create or edit content using interactive mode and language translation. • AI powered analytics • Smart content creation using prompts which includes creating content, creating Akumina workflow, etc., • FrontEnd: AI powered widgets, conversational based content experience. Let the conversation drive the experience for employee productivity https://github.com/microsoft/semantic-kernel https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main https://learn.microsoft.com/en-us/semantic-kernel/
  • 22.
    Reference • What’s newin .NET8: https://learn.microsoft.com/en-us/dotnet/core/whats- new/dotnet-8 • Performance Improvements ASP.NET Core: https://devblogs.microsoft.com/dotnet/performance-improvements-in-aspnet-core-8/ • Performance Improvements MAUI : https://devblogs.microsoft.com/dotnet/dotnet-8- performance-improvements-in-dotnet-maui/ • RoadMap: https://themesof.net/roadmap?product=.NET&release=8.0 • C#12: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12 • F#8: https://devblogs.microsoft.com/dotnet/announcing-fsharp-8 • Benchmarks: https://aka.ms/aspnet/benchmarks • Demo Samples: https://github.com/nhcloud/techtalk

Editor's Notes

  • #4 every release we improve performance in the runtime, BCL (base class library), & ASP.NET Core, MAUI
  • #6 Do once and cache it
  • #7 $env:DOTNET_JitDisasmSummary=1 Dotnet <pathtodll>
  • #8 Do once and cache it
  • #9 Do once and cache it
  • #10 Do once and cache it
  • #14 functional imp. required and init member support polymorphism and unspeakable type support string enum support for native aot Console App 23% and ASP.NET 57% <JsonSerializerIsReflectionEnabledByDefault>false</> JsonSerialier.Serialize(new {Value=42}); //System.InalidOperationexcption: refection-based serialization has been disable o this application JSON Fast Paths - Serializer and deserializer uses reflection, runtime analysis into build time so no more reflection JSON sealizer to stream –serializer the stream in async
  • #15 Performance Improvements in ASP.NET Core 8 - .NET Blog (microsoft.com) Allocate array of 4K, copy into new array and processing, no allocations, allocations from 7.8G to 2GB Not allocated if the bytes are <256 Avoid double dispatching Builder.WebHost.UseHttpSys(options=>{options.EnableKernelResponseBuffering=true}(); -- helpful when large file download; write or buffer your write
  • #16 Dotnet publish –r win-x64 –c release Reduce size on disk (Trim what we don’t use) Improve startupu time (make things pay for play) Lower the momory footprint (allocate less and improve the GC) 15MB Var builder=WebApplication.CeateEmptyBuilder(new WebApplicationOptions(){Args=args}); Builder.WebHost.UseKestrelCOre(); Var app=builder.Build(); App.Run(p=>p.Response.WriteAsync(“hello world”)); App.Run() Ahead-of-time compilation (AOT): A technique in computer programming where code is compiled before it is executed. This can improve performance by reducing the amount of work that the computer has to do at runtime.
  • #17 Dotnet publish –r win-x64 –c release Reduce size on disk (Trim what we don’t use) Improve startupu time (make things pay for play) Lower the momory footprint (allocate less and improve the GC) 15MB Var builder=WebApplication.CeateEmptyBuilder(new WebApplicationOptions(){Args=args}); Builder.WebHost.UseKestrelCOre(); Var app=builder.Build(); App.Run(p=>p.Response.WriteAsync(“hello world”)); App.Run() Ahead-of-time compilation (AOT): A technique in computer programming where code is compiled before it is executed. This can improve performance by reducing the amount of work that the computer has to do at runtime.
  • #19 Dotnet publish –r win-x64 –c release Reduce size on disk (Trim what we don’t use) Improve startupu time (make things pay for play) Lower the momory footprint (allocate less and improve the GC) 15MB Var builder=WebApplication.CeateEmptyBuilder(new WebApplicationOptions(){Args=args}); Builder.WebHost.UseKestrelCOre(); Var app=builder.Build(); App.Run(p=>p.Response.WriteAsync(“hello world”)); App.Run() Ahead-of-time compilation (AOT): A technique in computer programming where code is compiled before it is executed. This can improve performance by reducing the amount of work that the computer has to do at runtime.
  • #20 Performance Improvements in ASP.NET Core 8 - .NET Blog (microsoft.com) Allocate array of 4K, copy into new array and processing, no allocations, allocations from 7.8G to 2GB Not allocated if the bytes are <256 Avoid double dispatching Builder.WebHost.UseHttpSys(options=>{options.EnableKernelResponseBuffering=true}(); -- helpful when large file download
  • #21 https://www.youtube.com/watch?v=YiOkz1x2qaE&list=PLdo4fOcmZ0oULyHSPBx-tQzePOYlhvrAU&index=5 .NET DSrouter is a tool that enables diagnostic tools to communicate with a remote .NET runtime as if it has been running on the local machine. This can be useful for debugging and troubleshooting .NET applications that are running on servers, containers, or other devices.
  • #22 Plugins: Augment AI systems to access APIs Retrieve useful information Perform new computations Safely act on the user's behalf copilot<--plugins-->digital info https://github.com/johnmaeda/Mr-Maeda-Cozy-AI-Kitchen/blob/main/DesigningTrust/plugins-sk/TrustToychest/MindControl/skprompt.txt https://devblogs.microsoft.com/semantic-kernel/ https://devblogs.microsoft.com/semantic-kernel/unveiling-the-next-steps-in-ai-productivity-plugins-planners-and-personas-at-microsoft-ignite/ https://github.com/microsoft/podcastcopilot https://github.com/Azure-Samples/miyagi
  • #23 https://devblogs.microsoft.com/dotnet/getting-started-azure-openai-dotnet/ https://www.youtube.com/playlist?list=PLlrxD0HtieHjolPmqWVyk446uLMPWo4oP -- BUILD 2023 https://www.youtube.com/watch?v=1eHjemGKfRw --.NET 8 Perf https://platform.openai.com/examples --OpenAI Examples https://dotnet.microsoft.com/en-us/next --.NET 8 Page https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main https://learn.microsoft.com/en-us/semantic-kernel/ https://www.youtube.com/watch?v=zhCRX3B7qwY https://codetraveler.io/asyncawaitbestpractices/