SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
Writing High Performance C# 7 Code
Fons Sonnemans
@fonssonnemans
Fons Sonnemans
• Software Development Consultant
• Programming Languages
• Clipper, Smalltalk, Visual Basic, C#
• Platforms
• Windows Forms, ASP.NET, XAML (Silverlight, WPF, Windows Phone, Windows 10, Blend)
• Databases
• MS SQL Server, Oracle
• Role
• Trainer, Coach, Advisor, Architect, Designer, Windows App Developer
• www.reflectionit.nl/training
• www.reflectionit.nl/apps
2
Audience
• Who is not a Software Developer
• Who is not a C# developer
• Who is not using C# 7
• Who is not using C# 7.3
• Who is not using .NET Core 2.0 or 2.1
• Who is not creating 64 bits apps
• Who is not using ReSharper
• Who is not using (or writing) Code Analyzers
• Who does not understand the .NET Garbage Collector (GC)
• Who is not having Performance Issues
• Who is not writing Structs
3
How to solve Performance Issues
• Choose fast algorithms
• Choose optimal data structures
• Optimize memory usage
• Implement caching
• Think over architecture
• Layers, Tiers, UI, (Web) API, Message Queues, Cloud, Security, Transactions
(locking), Threading (async)
• Optimize networking (HTTP, SQL)
• Work chunky not chatty
• Optimize I/O
• Where are you writing your Trace information, files, databases, cloud or ETW?
• https://www.youtube.com/watch?v=XfkpjlP0Nq4
4
What’s new in C# 7
• C# 7.0
• Out Variables
• Binary literals & Digit separators
• Pattern Matching
• Local Functions
• Tuples
• Deconstruction
• Discards
• More expression bodied members
• Throw expressions
• Generalized async return types
• Ref Returns and Ref Locals
• C# 7.1
• Default Expressions
• async Main
• Infer tuple names
• Pattern-matching with Generics
• C# 7.2
• Reference semantics with value types
• In parameters, ref readonly, readonly struct, ref struct
• private protected access modifier
• Non-trailing named arguments
• Ref & In Extension Methods
• Conditional Ref Operator
• C# 7.3
• new generic constraints
• Attributes on backing fields
• Ref local re-assignment
• Stackalloc initializers
• Expression variables in initializers
• Tuple comparison
• Improved overload candidates
Topics
• Measuring & Tools
• Stopwatch
• Diagnostic Tools
• Performance Profiler
• Benchmark.NET
• ILSpy & SharpLab.io
• Garbage Collection
• Large Object Heap
• Collection Capacity
• ArrayPool<T>
• Writing Structs
• C# 7.0: Anonymous Types vs ValueTuples
• BigStruct: ByValue & ByRef
• StuctLayout
• Boxing & Unboxing
• CLR Heap Allocation Analyzer
• Equals & GetHashCode
• Defensive Copy
• C# 7.x
• In parameters,
• Ref (Readonly) Return & Ref (Readonly) Local
• Readonly structs
• ErrorProne.NET.Structs
• Ref structs, Span<T>, Stackalloc
6
Heap
Reference Types + Value Types storedin Fields of Reference Types
.NET Memory - Stack & Heap
7
Stack
Value Types + Pointers
1MB on 32Bit
4MB on 64Bit
Thread
1
CPU Cache
L1 -> L2 -> L3
Thread
2
Thread
N
Large Object Heap
Objects larger than 85KB,
mostly arrays
Gen 2 + Not Compacted
?
Small Object Heap
Gen 0
Short-lived
~256KB
Gen 1
“Buffer”
~2MB
Gen 2
Long-lived
~10MB
GC GC
L2
Code
Heap
Process
Heap
Value Types vs. Reference Types
• Memory Overhead
• http://adamsitnik.com/Value-Types-vs-Reference-Types/
• Value Type (PointStruct)
• Reference Type (PointClass)
8
X Y
X
Y
Total: 8 Bytes
Total: 8 Bytes
Total: 16 Bytes
Total: 24 Bytes
@fonssonnemans
fons.sonnemans@reflectionit.nl
fonssonnemans
reflectionit.nl/blog
9
https://reflectionit.nl/training/csharp
10

Contenu connexe

Tendances

JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should CareJOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should CareJordan Open Source Association
 
Learning Silicon Valley Culture
Learning Silicon Valley CultureLearning Silicon Valley Culture
Learning Silicon Valley CultureTaro L. Saito
 
Open Source Tools and the Software Engineering Process
Open Source Tools and the Software Engineering ProcessOpen Source Tools and the Software Engineering Process
Open Source Tools and the Software Engineering ProcessSteve Arnold
 
Intelligent System Scripting Language - Conceptual Presentation
Intelligent System Scripting Language - Conceptual PresentationIntelligent System Scripting Language - Conceptual Presentation
Intelligent System Scripting Language - Conceptual PresentationCédric Poottaren
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvmNLJUG
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
Thing to love in Clojure
Thing to love in ClojureThing to love in Clojure
Thing to love in ClojureJiří Knesl
 
C++ in object oriented programming
C++ in object oriented programmingC++ in object oriented programming
C++ in object oriented programmingSaket Khopkar
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 

Tendances (13)

JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should CareJOSA TechTalks - Compilers, Transpilers, and Why You Should Care
JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
 
Learning Silicon Valley Culture
Learning Silicon Valley CultureLearning Silicon Valley Culture
Learning Silicon Valley Culture
 
Open Source Tools and the Software Engineering Process
Open Source Tools and the Software Engineering ProcessOpen Source Tools and the Software Engineering Process
Open Source Tools and the Software Engineering Process
 
Short and fast introduction to Scala
Short and fast introduction to ScalaShort and fast introduction to Scala
Short and fast introduction to Scala
 
Intelligent System Scripting Language - Conceptual Presentation
Intelligent System Scripting Language - Conceptual PresentationIntelligent System Scripting Language - Conceptual Presentation
Intelligent System Scripting Language - Conceptual Presentation
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Thing to love in Clojure
Thing to love in ClojureThing to love in Clojure
Thing to love in Clojure
 
C++ in object oriented programming
C++ in object oriented programmingC++ in object oriented programming
C++ in object oriented programming
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Scala goods bads
Scala goods badsScala goods bads
Scala goods bads
 

Similaire à Writing High Peformance C# 7 Code

C# 9 and 10 - What's cool?
C# 9 and 10 - What's cool?C# 9 and 10 - What's cool?
C# 9 and 10 - What's cool?Christian Nagel
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development SecuritySam Bowne
 
C# 9 - What's the cool stuff? - BASTA! Spring 2021
C# 9 - What's the cool stuff? - BASTA! Spring 2021C# 9 - What's the cool stuff? - BASTA! Spring 2021
C# 9 - What's the cool stuff? - BASTA! Spring 2021Christian Nagel
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecuritySam Bowne
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development SecuritySam Bowne
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code ReviewMilan Vukoje
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...Speedment, Inc.
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadSoftware Guru
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreChristian Nagel
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Christian Nagel
 
Full Stack Developer Course | Infinite Graphix Technologies
Full Stack Developer Course | Infinite Graphix TechnologiesFull Stack Developer Course | Infinite Graphix Technologies
Full Stack Developer Course | Infinite Graphix TechnologiesInfinite Graphix Technologies
 
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?Clint Edmonson
 
Internet Marketing Institute in Delhi
Internet Marketing Institute in DelhiInternet Marketing Institute in Delhi
Internet Marketing Institute in DelhiJessica Smith
 
Punta Dreamin 17 Generic Apex and Tooling Api
Punta Dreamin 17 Generic Apex and Tooling ApiPunta Dreamin 17 Generic Apex and Tooling Api
Punta Dreamin 17 Generic Apex and Tooling ApiAdam Olshansky
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 

Similaire à Writing High Peformance C# 7 Code (20)

C# 9 and 10 - What's cool?
C# 9 and 10 - What's cool?C# 9 and 10 - What's cool?
C# 9 and 10 - What's cool?
 
C# 8 and .NET Core 3
C# 8 and .NET Core 3C# 8 and .NET Core 3
C# 8 and .NET Core 3
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
C# 9 - What's the cool stuff? - BASTA! Spring 2021
C# 9 - What's the cool stuff? - BASTA! Spring 2021C# 9 - What's the cool stuff? - BASTA! Spring 2021
C# 9 - What's the cool stuff? - BASTA! Spring 2021
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development Security
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Node.js architecture (EN)
Node.js architecture (EN)Node.js architecture (EN)
Node.js architecture (EN)
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidad
 
SGCE 2015 REST APIs
SGCE 2015 REST APIsSGCE 2015 REST APIs
SGCE 2015 REST APIs
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
Full Stack Developer Course | Infinite Graphix Technologies
Full Stack Developer Course | Infinite Graphix TechnologiesFull Stack Developer Course | Infinite Graphix Technologies
Full Stack Developer Course | Infinite Graphix Technologies
 
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
 
Internet Marketing Institute in Delhi
Internet Marketing Institute in DelhiInternet Marketing Institute in Delhi
Internet Marketing Institute in Delhi
 
Punta Dreamin 17 Generic Apex and Tooling Api
Punta Dreamin 17 Generic Apex and Tooling ApiPunta Dreamin 17 Generic Apex and Tooling Api
Punta Dreamin 17 Generic Apex and Tooling Api
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Mca sem1syll
Mca sem1syllMca sem1syll
Mca sem1syll
 

Plus de Fons Sonnemans

New XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators UpdateNew XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators UpdateFons Sonnemans
 
Coding for kids - TechDays 2017
Coding for kids - TechDays 2017Coding for kids - TechDays 2017
Coding for kids - TechDays 2017Fons Sonnemans
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...Fons Sonnemans
 
Developing and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsDeveloping and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsFons Sonnemans
 
What's new in Blend for Visual Studio 2015
What's new in Blend for Visual Studio 2015What's new in Blend for Visual Studio 2015
What's new in Blend for Visual Studio 2015Fons Sonnemans
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Fons Sonnemans
 
Coding for kids - TechDaysNL 2015
Coding for kids - TechDaysNL 2015Coding for kids - TechDaysNL 2015
Coding for kids - TechDaysNL 2015Fons Sonnemans
 
Twelve ways to make your apps suck less
Twelve ways to make your apps suck lessTwelve ways to make your apps suck less
Twelve ways to make your apps suck lessFons Sonnemans
 
What’s new in XAML and Tooling for Windows 8.1
What’s new in XAML and Tooling for Windows 8.1What’s new in XAML and Tooling for Windows 8.1
What’s new in XAML and Tooling for Windows 8.1Fons Sonnemans
 
Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Fons Sonnemans
 
Making money with apps
Making money with appsMaking money with apps
Making money with appsFons Sonnemans
 

Plus de Fons Sonnemans (12)

Xamarin Froms 4.x
Xamarin Froms 4.xXamarin Froms 4.x
Xamarin Froms 4.x
 
New XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators UpdateNew XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators Update
 
Coding for kids - TechDays 2017
Coding for kids - TechDays 2017Coding for kids - TechDays 2017
Coding for kids - TechDays 2017
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
Developing and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsDeveloping and Deploying Windows 10 Apps
Developing and Deploying Windows 10 Apps
 
What's new in Blend for Visual Studio 2015
What's new in Blend for Visual Studio 2015What's new in Blend for Visual Studio 2015
What's new in Blend for Visual Studio 2015
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
 
Coding for kids - TechDaysNL 2015
Coding for kids - TechDaysNL 2015Coding for kids - TechDaysNL 2015
Coding for kids - TechDaysNL 2015
 
Twelve ways to make your apps suck less
Twelve ways to make your apps suck lessTwelve ways to make your apps suck less
Twelve ways to make your apps suck less
 
What’s new in XAML and Tooling for Windows 8.1
What’s new in XAML and Tooling for Windows 8.1What’s new in XAML and Tooling for Windows 8.1
What’s new in XAML and Tooling for Windows 8.1
 
Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013Designing XAML apps using Blend for Visual Studio 2013
Designing XAML apps using Blend for Visual Studio 2013
 
Making money with apps
Making money with appsMaking money with apps
Making money with apps
 

Dernier

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 

Dernier (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Writing High Peformance C# 7 Code

  • 1. Writing High Performance C# 7 Code Fons Sonnemans @fonssonnemans
  • 2. Fons Sonnemans • Software Development Consultant • Programming Languages • Clipper, Smalltalk, Visual Basic, C# • Platforms • Windows Forms, ASP.NET, XAML (Silverlight, WPF, Windows Phone, Windows 10, Blend) • Databases • MS SQL Server, Oracle • Role • Trainer, Coach, Advisor, Architect, Designer, Windows App Developer • www.reflectionit.nl/training • www.reflectionit.nl/apps 2
  • 3. Audience • Who is not a Software Developer • Who is not a C# developer • Who is not using C# 7 • Who is not using C# 7.3 • Who is not using .NET Core 2.0 or 2.1 • Who is not creating 64 bits apps • Who is not using ReSharper • Who is not using (or writing) Code Analyzers • Who does not understand the .NET Garbage Collector (GC) • Who is not having Performance Issues • Who is not writing Structs 3
  • 4. How to solve Performance Issues • Choose fast algorithms • Choose optimal data structures • Optimize memory usage • Implement caching • Think over architecture • Layers, Tiers, UI, (Web) API, Message Queues, Cloud, Security, Transactions (locking), Threading (async) • Optimize networking (HTTP, SQL) • Work chunky not chatty • Optimize I/O • Where are you writing your Trace information, files, databases, cloud or ETW? • https://www.youtube.com/watch?v=XfkpjlP0Nq4 4
  • 5. What’s new in C# 7 • C# 7.0 • Out Variables • Binary literals & Digit separators • Pattern Matching • Local Functions • Tuples • Deconstruction • Discards • More expression bodied members • Throw expressions • Generalized async return types • Ref Returns and Ref Locals • C# 7.1 • Default Expressions • async Main • Infer tuple names • Pattern-matching with Generics • C# 7.2 • Reference semantics with value types • In parameters, ref readonly, readonly struct, ref struct • private protected access modifier • Non-trailing named arguments • Ref & In Extension Methods • Conditional Ref Operator • C# 7.3 • new generic constraints • Attributes on backing fields • Ref local re-assignment • Stackalloc initializers • Expression variables in initializers • Tuple comparison • Improved overload candidates
  • 6. Topics • Measuring & Tools • Stopwatch • Diagnostic Tools • Performance Profiler • Benchmark.NET • ILSpy & SharpLab.io • Garbage Collection • Large Object Heap • Collection Capacity • ArrayPool<T> • Writing Structs • C# 7.0: Anonymous Types vs ValueTuples • BigStruct: ByValue & ByRef • StuctLayout • Boxing & Unboxing • CLR Heap Allocation Analyzer • Equals & GetHashCode • Defensive Copy • C# 7.x • In parameters, • Ref (Readonly) Return & Ref (Readonly) Local • Readonly structs • ErrorProne.NET.Structs • Ref structs, Span<T>, Stackalloc 6
  • 7. Heap Reference Types + Value Types storedin Fields of Reference Types .NET Memory - Stack & Heap 7 Stack Value Types + Pointers 1MB on 32Bit 4MB on 64Bit Thread 1 CPU Cache L1 -> L2 -> L3 Thread 2 Thread N Large Object Heap Objects larger than 85KB, mostly arrays Gen 2 + Not Compacted ? Small Object Heap Gen 0 Short-lived ~256KB Gen 1 “Buffer” ~2MB Gen 2 Long-lived ~10MB GC GC L2 Code Heap Process Heap
  • 8. Value Types vs. Reference Types • Memory Overhead • http://adamsitnik.com/Value-Types-vs-Reference-Types/ • Value Type (PointStruct) • Reference Type (PointClass) 8 X Y X Y Total: 8 Bytes Total: 8 Bytes Total: 16 Bytes Total: 24 Bytes