SlideShare a Scribd company logo
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

More Related Content

What's hot (13)

PDF
JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
Jordan Open Source Association
 
PDF
Learning Silicon Valley Culture
Taro L. Saito
 
PDF
Open Source Tools and the Software Engineering Process
Steve Arnold
 
PDF
Short and fast introduction to Scala
Sergi González Pérez
 
PPTX
Intelligent System Scripting Language - Conceptual Presentation
Cédric Poottaren
 
PDF
Shootout! template engines on the jvm
NLJUG
 
PDF
1.6 米嘉 gobuildweb
Leo Zhou
 
PPTX
Thing to love in Clojure
Jiří Knesl
 
PPTX
C++ in object oriented programming
Saket Khopkar
 
PPTX
Day 8 - jRuby
Barry Jones
 
PPTX
Day 1 - Intro to Ruby
Barry Jones
 
PDF
Code for Startup MVP (Ruby on Rails) Session 1
Henry S
 
PDF
Scala goods bads
Diego Pacheco
 
JOSA TechTalks - Compilers, Transpilers, and Why You Should Care
Jordan Open Source Association
 
Learning Silicon Valley Culture
Taro L. Saito
 
Open Source Tools and the Software Engineering Process
Steve Arnold
 
Short and fast introduction to Scala
Sergi González Pérez
 
Intelligent System Scripting Language - Conceptual Presentation
Cédric Poottaren
 
Shootout! template engines on the jvm
NLJUG
 
1.6 米嘉 gobuildweb
Leo Zhou
 
Thing to love in Clojure
Jiří Knesl
 
C++ in object oriented programming
Saket Khopkar
 
Day 8 - jRuby
Barry Jones
 
Day 1 - Intro to Ruby
Barry Jones
 
Code for Startup MVP (Ruby on Rails) Session 1
Henry S
 
Scala goods bads
Diego Pacheco
 

Similar to Writing High Peformance C# 7 Code (20)

PDF
C# 9 and 10 - What's cool?
Christian Nagel
 
PDF
C# 8 and .NET Core 3
Christian Nagel
 
PDF
8. Software Development Security
Sam Bowne
 
PDF
C# 9 - What's the cool stuff? - BASTA! Spring 2021
Christian Nagel
 
PDF
CISSP Prep: Ch 9. Software Development Security
Sam Bowne
 
PDF
8. Software Development Security
Sam Bowne
 
PPTX
Introduction to C#.pptx for all BSIT students
julie4baxtii
 
PPTX
Coding Standard And Code Review
Milan Vukoje
 
PPTX
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
PPTX
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
ODP
Node.js architecture (EN)
Timur Shemsedinov
 
PDF
APIs distribuidos con alta escalabilidad
Software Guru
 
PDF
SGCE 2015 REST APIs
Domingo Suarez Torres
 
PDF
Reference Semantics with C# and .NET Core
Christian Nagel
 
PDF
Reference Semantik mit C# und .NET Core - BASTA 2019
Christian Nagel
 
PDF
Full Stack Developer Course | Infinite Graphix Technologies
Infinite Graphix Technologies
 
PPTX
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
Clint Edmonson
 
PDF
Internet Marketing Institute in Delhi
Jessica Smith
 
PDF
Punta Dreamin 17 Generic Apex and Tooling Api
Adam Olshansky
 
PDF
Using Scala for building DSLs
IndicThreads
 
C# 9 and 10 - What's cool?
Christian Nagel
 
C# 8 and .NET Core 3
Christian Nagel
 
8. Software Development Security
Sam Bowne
 
C# 9 - What's the cool stuff? - BASTA! Spring 2021
Christian Nagel
 
CISSP Prep: Ch 9. Software Development Security
Sam Bowne
 
8. Software Development Security
Sam Bowne
 
Introduction to C#.pptx for all BSIT students
julie4baxtii
 
Coding Standard And Code Review
Milan Vukoje
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
Node.js architecture (EN)
Timur Shemsedinov
 
APIs distribuidos con alta escalabilidad
Software Guru
 
SGCE 2015 REST APIs
Domingo Suarez Torres
 
Reference Semantics with C# and .NET Core
Christian Nagel
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Christian Nagel
 
Full Stack Developer Course | Infinite Graphix Technologies
Infinite Graphix Technologies
 
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
Clint Edmonson
 
Internet Marketing Institute in Delhi
Jessica Smith
 
Punta Dreamin 17 Generic Apex and Tooling Api
Adam Olshansky
 
Using Scala for building DSLs
IndicThreads
 
Ad

More from Fons Sonnemans (12)

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

Recently uploaded (20)

PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 

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