SlideShare a Scribd company logo
©2016 GlobalLogic Inc.
2
.NET Performance Boost
By Andrii Antilikatorov
3
4
Optimize or not optimize?
5
6
7
8
Quiz
9
Jagged arrays vs 2D arrays
4571ns2864ns
10
Jagged arrays
11
FOR vs FOREACH
12
FOR vs FOREACH
… it depends
13
FOR vs FOREACH
14
Performance of try...catch
2555ns 674ns
15
Create new collection or clear existing one?
645ns
501ns
16
String pool
Can be disabled with CompilationRelaxationsAttribute
By default interns only string literals
Works great in multithreaded code
Has the same lifetime as CLR
May cause troubles if interning went out of control
17
Avoiding Boxing
bool areEqual = v1.Equals(v2);
18
Avoiding Boxing
bool areEqual = v1.Equals(v2);
19
Avoiding Boxing
20
Avoiding Boxing
21
Avoiding Boxing
22
Avoiding Boxing
23
Avoiding Boxing
Use value types if objects are small and supposed to be used often.
Value types are useful for memory compaction.
Override Equals(), “==“ (“!=“). Implement IEquatable interface.
Override GetHashCode().
Make value types immutable.
24
Cost of method calls
CALL
CALLVIRTDependency Injection
25
Parameter order performance
952ms
2224ms
26
Field access optimization
15.86ns
27
Field access optimization
5.18ns
28
Multiple return values
1.64ns
0.32ns
5.40ns
29
Tuple/KeyValuePair performance
Tuple KeyValuePair
Allocate 8.23ns 0.32ns
Pass as argument 1.93ns 2.57ns
Return 6.09ns 1.91ns
Load from List 2.79ns 4.18ns
30
Array Copy
1343ns
1013ns
31
Performance of DateTime
264ns
16 ns
32
Memory Access
Off-Heap
(Unmanaged)
Memory-Mapped Files
Heap
(Managed)
1.068s1.096s
LOH optimization
P/Invoke, COM, Marshalling
33
Memory-Mapped Files
Ideal to access file on disk without
performing I/O operations
The most efficient for cross-
process communication.
Allows properly protecting the
content and synchronize access.
34
Memory Alignment
Type alignment Page size alignment
Cache line alignment
Memory Alignment
35
Comparing Aligned/Unaligned Access Performance
Type aligned access provides better performance than
unaligned access.
Memory access that spans 2 cache lines has far worse
performance than aligned mid-cache line access.
Cache line access performance changes based on
cache line location.
36
Type-aligned vs unaligned Access Test
Number of pages
Alignment
Relative cost
37
Comparing Aligned/Unaligned Access Performance
Type aligned access provides better performance than
unaligned access.
Memory access that spans 2 cache lines has far worse
performance than aligned mid-cache line access.
Cache line access performance changes based on
cache line location.
38
Cross-line cache access
Number of pages
Offset
Relative cost
39
Comparing Aligned/Unaligned Access Performance
Type aligned access provides better performance than
unaligned access.
Memory access that spans 2 cache lines has far worse
performance than aligned mid-cache line access.
Cache line access performance changes based on
cache line location.
40
Comparing Aligned/Unaligned Access Performance
Type aligned access provides better performance than
unaligned access.
Memory access that spans 2 cache lines has far worse
performance than aligned mid-cache line access.
Cache line access performance changes based on
cache line location.
41
Cost of Access Based on Cache Line Location
Offset
Number of pagesRelative cost
42
Comparing Aligned/Unaligned Access Performance
Type aligned access provides better performance than
unaligned access.
Memory access that spans 2 cache lines has far worse
performance than aligned mid-cache line access.
Cache line access performance changes based on
cache line location.
43
Synchronized or volatile?
Volatile variables are less expensive than synchronized blocks
Volatile are thread-safe for atomic operations
Volatile acquires lock on variable, therefore not thread- safe
for non-atomic operations
Synchronized blocks have no performance impact if no
synchronization required
44
Synchronized or volatile?
45
Synchronized or volatile?
MESI Protocol
• Modified
• Exclusive
• Shared
• Invalid
46
Synchronized or volatile?
Volatile variables are less expensive than synchronized blocks
Volatile are thread-safe for atomic operations
Volatile acquires lock on variable, therefore not thread- safe
for non-atomic operations
Synchronized blocks have no performance impact if no
synchronization required
47
Summary
Architecture first
Remember rule 80/20
Don’t try to write ideal code from the beginning
Don’t create bicycles
Don’t optimize for particular platform
©2016 GlobalLogic Inc.

More Related Content

What's hot (14)

PDF
cache2k, Java Caching, Turbo Charged, FOSDEM 2015
cruftex
 
PDF
The need for speed. What is GraalVM? – 4Developers Wrocław 2019
Maciej Przepióra
 
KEY
Blocks & Grand Central Dispatch
Robin Lu
 
PDF
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India
 
PDF
Java 8 고급 (4/6)
Kyung Koo Yoon
 
PDF
Grand Central Dispatch - iOS Conf SG 2015
Ben Asher
 
PDF
LCU14 209- LLVM Linux
Linaro
 
PDF
GCD and OperationQueue.
HSIEH CHING-FAN
 
KEY
Concurrent Programming Using the Disruptor
Trisha Gee
 
PDF
Performance tests with gatling
SoftwareMill
 
PPTX
Ob1k presentation at Java.IL
Eran Harel
 
PPT
Oreilly Webcast Jun17
Sean Hull
 
PPTX
Q Con Performance Testing At The Edge
Alois Reitbauer
 
PPTX
Low latency microservices in java QCon New York 2016
Peter Lawrey
 
cache2k, Java Caching, Turbo Charged, FOSDEM 2015
cruftex
 
The need for speed. What is GraalVM? – 4Developers Wrocław 2019
Maciej Przepióra
 
Blocks & Grand Central Dispatch
Robin Lu
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India
 
Java 8 고급 (4/6)
Kyung Koo Yoon
 
Grand Central Dispatch - iOS Conf SG 2015
Ben Asher
 
LCU14 209- LLVM Linux
Linaro
 
GCD and OperationQueue.
HSIEH CHING-FAN
 
Concurrent Programming Using the Disruptor
Trisha Gee
 
Performance tests with gatling
SoftwareMill
 
Ob1k presentation at Java.IL
Eran Harel
 
Oreilly Webcast Jun17
Sean Hull
 
Q Con Performance Testing At The Edge
Alois Reitbauer
 
Low latency microservices in java QCon New York 2016
Peter Lawrey
 

Viewers also liked (9)

PPT
Business-IT Alignment
Walter Adamson
 
PPT
8086 micro processor
Poojith Chowdhary
 
PPT
0 introduction to computer architecture
aamc1100
 
PPTX
Microprocessor 8086
Gopikrishna Madanan
 
PPTX
8086 microprocessor-architecture
prasadpawaskar
 
PPTX
BASIC COMPUTER ARCHITECTURE
Himanshu Sharma
 
PPT
Ntroduction to computer architecture and organization
Fakulti seni, komputeran dan indusri kreatif
 
PPT
Computer architecture
Rishabha Garg
 
PDF
The Top Skills That Can Get You Hired in 2017
LinkedIn
 
Business-IT Alignment
Walter Adamson
 
8086 micro processor
Poojith Chowdhary
 
0 introduction to computer architecture
aamc1100
 
Microprocessor 8086
Gopikrishna Madanan
 
8086 microprocessor-architecture
prasadpawaskar
 
BASIC COMPUTER ARCHITECTURE
Himanshu Sharma
 
Ntroduction to computer architecture and organization
Fakulti seni, komputeran dan indusri kreatif
 
Computer architecture
Rishabha Garg
 
The Top Skills That Can Get You Hired in 2017
LinkedIn
 
Ad

Similar to .NET Performance Boost (20)

PPTX
Performance is a Feature!
PostSharp Technologies
 
PPTX
Performance is a feature! - London .NET User Group
Matt Warren
 
PPTX
Performance and how to measure it - ProgSCon London 2016
Matt Warren
 
PDF
Look Mommy, no GC! (BrightSource)
Dina Goldshtein
 
PPT
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
Daniel Fisher
 
PPTX
Performance is a Feature! at DDD 11
Matt Warren
 
PPTX
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
PPTX
Whats New In 2010 (Msdn & Visual Studio)
Steve Lange
 
PDF
Performance optimization techniques for Java code
Attila Balazs
 
PPTX
Perf by design
Tess Ferrandez
 
PPTX
Performance is a feature! - Developer South Coast - part 2
Matt Warren
 
PDF
Look Mommy, No GC! (Codecamp Iasi 2017)
Dina Goldshtein
 
PPSX
Scaling Application
Alaor Bianco
 
PDF
Performance and predictability
RichardWarburton
 
PDF
Performance Tuning of .NET Application
Mainul Islam, CSM®
 
PDF
Performance and predictability (1)
RichardWarburton
 
PDF
Performance and Predictability - Richard Warburton
JAXLondon2014
 
PPTX
"Making .NET Application Even Faster", Sergey Teplyakov.pptx
Fwdays
 
PDF
High Performance Managed Languages
J On The Beach
 
PPT
Gdc03 ericson memory_optimization
brettlevin
 
Performance is a Feature!
PostSharp Technologies
 
Performance is a feature! - London .NET User Group
Matt Warren
 
Performance and how to measure it - ProgSCon London 2016
Matt Warren
 
Look Mommy, no GC! (BrightSource)
Dina Goldshtein
 
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
Daniel Fisher
 
Performance is a Feature! at DDD 11
Matt Warren
 
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
Whats New In 2010 (Msdn & Visual Studio)
Steve Lange
 
Performance optimization techniques for Java code
Attila Balazs
 
Perf by design
Tess Ferrandez
 
Performance is a feature! - Developer South Coast - part 2
Matt Warren
 
Look Mommy, No GC! (Codecamp Iasi 2017)
Dina Goldshtein
 
Scaling Application
Alaor Bianco
 
Performance and predictability
RichardWarburton
 
Performance Tuning of .NET Application
Mainul Islam, CSM®
 
Performance and predictability (1)
RichardWarburton
 
Performance and Predictability - Richard Warburton
JAXLondon2014
 
"Making .NET Application Even Faster", Sergey Teplyakov.pptx
Fwdays
 
High Performance Managed Languages
J On The Beach
 
Gdc03 ericson memory_optimization
brettlevin
 
Ad

More from GlobalLogic Ukraine (20)

PDF
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
GlobalLogic Ukraine
 
PPTX
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
PDF
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Ukraine
 
PDF
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic Ukraine
 
PPTX
Штучний інтелект як допомога в навчанні, а не замінник.pptx
GlobalLogic Ukraine
 
PPTX
Задачі AI-розробника як застосовується штучний інтелект.pptx
GlobalLogic Ukraine
 
PPTX
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Ukraine
 
PDF
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic Ukraine
 
PDF
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic Ukraine
 
PPTX
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic Ukraine
 
PDF
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic Ukraine
 
PDF
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic Ukraine
 
PDF
“How to Secure Your Applications With a Keycloak?
GlobalLogic Ukraine
 
PDF
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 
PPTX
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Ukraine
 
PDF
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic Ukraine
 
PDF
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic Ukraine
 
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
GlobalLogic Ukraine
 
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Ukraine
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic Ukraine
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
GlobalLogic Ukraine
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
GlobalLogic Ukraine
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Ukraine
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic Ukraine
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic Ukraine
 
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic Ukraine
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic Ukraine
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic Ukraine
 
“How to Secure Your Applications With a Keycloak?
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Ukraine
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic Ukraine
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic Ukraine
 

Recently uploaded (20)

PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
Understanding the EU Cyber Resilience Act
ICS
 
PDF
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 31 2025?
utfefguu
 
PDF
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
PPTX
API DOCUMENTATION | API INTEGRATION PLATFORM
philipnathen82
 
PDF
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PDF
Instantiations Company Update (ESUG 2025)
ESUG
 
PDF
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
PDF
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
 
PDF
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
PDF
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
 
PDF
Optimizing Tiered Storage for Low-Latency Real-Time Analytics at AI Scale
Alluxio, Inc.
 
PPTX
How Odoo ERP Enhances Operational Visibility Across Your Organization.pptx
pintadoxavier667
 
PPTX
How Odoo ERP Enhances Operational Visibility Across Your Organization.pptx
zidanakhtar874
 
PDF
Message Level Status (MLS): The Instant Feedback Mechanism for UAE e-Invoicin...
Prachi Desai
 
PPTX
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
Understanding the EU Cyber Resilience Act
ICS
 
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
IDM Crack with Internet Download Manager 6.42 Build 31 2025?
utfefguu
 
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
API DOCUMENTATION | API INTEGRATION PLATFORM
philipnathen82
 
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
Instantiations Company Update (ESUG 2025)
ESUG
 
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
 
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
ESUG 2025: Pharo 13 and Beyond (Stephane Ducasse)
ESUG
 
Optimizing Tiered Storage for Low-Latency Real-Time Analytics at AI Scale
Alluxio, Inc.
 
How Odoo ERP Enhances Operational Visibility Across Your Organization.pptx
pintadoxavier667
 
How Odoo ERP Enhances Operational Visibility Across Your Organization.pptx
zidanakhtar874
 
Message Level Status (MLS): The Instant Feedback Mechanism for UAE e-Invoicin...
Prachi Desai
 
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 

.NET Performance Boost

Editor's Notes

  • #9: https://raygun.com/blog/2014/02/c-sharp-performance-tips-tricks/ http://www.dotnetperls.com/jagged-array
  • #10: http://www.dotnetperls.com/jagged-array
  • #11: https://raygun.com/blog/2014/02/c-sharp-performance-tips-tricks/ http://www.dotnetperls.com/jagged-array
  • #12: http://www.dotnetperls.com/for-foreach http://www.dotnetperls.com/string-for-loop
  • #13: http://www.dotnetperls.com/for-foreach http://www.dotnetperls.com/string-for-loop
  • #14: http://www.dotnetperls.com/for-foreach http://www.dotnetperls.com/string-for-loop
  • #15: http://www.dotnetperls.com/exception-optimization
  • #16: http://www.dotnetperls.com/list-clear
  • #17: https://blog.jetbrains.com/dotnet/2015/02/12/string-interning-effective-memory-management-with-dotmemory/ https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilationrelaxationsattribute(v=vs.110).aspx http://www.dotnetperls.com/string-intern https://msdn.microsoft.com/en-us/library/system.string.intern(v=vs.110).aspx
  • #18: From book
  • #19: From book
  • #20: From book
  • #21: From book
  • #22: From book
  • #23: From book
  • #24: From book
  • #25: http://www.cyberforum.ru/csharp-net/thread1631924.html
  • #26: http://www.dotnetperls.com/method-parameter
  • #27: http://www.dotnetperls.com/local-variable-field-optimization
  • #28: http://www.dotnetperls.com/local-variable-field-optimization
  • #29: http://www.dotnetperls.com/multiple-return-values
  • #30: http://www.dotnetperls.com/tuple-keyvaluepair
  • #31: http://www.dotnetperls.com/buffer
  • #32: http://www.dotnetperls.com/datetime-performance
  • #33: http://ghost-doubleyewdee.azurewebsites.net/dotnet-pointer-fun/ https://nbsoftsolutions.com/blog/high-performance-unsafe-c-code-is-a-lie https://github.com/doubleyewdee/dotnet-fixed-benchmark/blob/master/src/Program.cs
  • #34: http://www.dotnetperls.com/memorymappedfile-benchmark https://ayende.com/blog/163138/memory-mapped-files-file-i-o-performance https://blogs.msdn.microsoft.com/salvapatuel/2009/06/08/working-with-memory-mapped-files-in-net-4/ https://msdn.microsoft.com/en-us/library/dd997372(v=vs.110).aspx