SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Performance Tuning of
.NET application
Md. Mainul Islam
Software Engineer, SELISE
mainul098@mail.com
✓ What is Performance Tuning?
✓ How to profile performance?
✓ Identify hotspot bottlenecks
✓ Ways to optimize .NET Application.
Why Are We Here?
Lets Explore
“Performance tuning is the improvement of
system performance”
Your app
Reality of Performance
You
Where is the Bottleneck?
for (int n = 2; n < 10000; ++n)
{
bool prime = true;
for (int d = 2; d < n; ++d)
{
if (n % d == 0)
{
prime = false;
break;
}
}
if (prime) Console.WriteLine(n);
}
“Premature optimization is the root
of all evil”
- Donald Knuth
Mistakes of Performance Tuning
✓ Optimize without a reliable measurement
✓ Optimize without verifying the results
✓ Relying on gut feeling
Performance Matrices
CPU
Execution time,
queuing
Memory
Utilization, load %
Disk
Utilization, I/O Operation
Network
Bandwidth, queueing
How does it work?
1. Select Application to Profile
2. Start Profiling
3. Collect Data and Detect Bottlenecks
4. Optimize Performance
5. Compare Profiling Results
6. Repeat Until Desired Results (Or
Possible)
dotTrace
+
dotMemory
Choosing a Collection
Dozens of Builtin Collections
✓ List<T>
✓ ArrayList<T>
✓ Dictionary<K,V>
✓ HashSet<T>
✓ Queue<T>
✓ SortedList<K,V>
✓ SortedDictionary<K,V>
✓ SortedSet<T>
✓ Stack<T>
… and more
Choose Proper Collection
■ Stop using List<T> for everything
■ Ask yourself:
Do you need to access each element by index?
For zero-based index: Use ArrayList and StringCollection classes and
the List<T> generic class.
For key based index: The Hashtable, SortedList, ListDictionary, and
StringDictionary classes, and the Dictionary<TKey, TValue> and
SortedDictionary<TKey, TValue> generic classes.
Do you need to sort your collection?
The Hashtable class sorts its elements by their hash codes.
The SortedDictionary<TKey, TValue> and SortedList<TKey, TValue> generic
classes sort their elements by the key.
Collection - (Contd.)
Do you need to search your collection?
ListDictionary is faster than Hashtable for small collections
(10 items or fewer).
The Dictionary<TKey, TValue> generic class provides faster
lookup than the SortedDictionary<TKey, TValue> generic class.
The multi-threaded implementation is
ConcurrentDictionary<TKey, TValue>. ConcurrentBag<T>
provides fast multi-threaded insertion for unordered data.
Do you need collections that accept only strings?
StringCollection (based on IList) and StringDictionary
(based on IDictionary).
Collection Ordering
Direct
Access?
Lookup
Efficiency
Manipulate
Efficiency
Notes
Dictionary Unordered Via Key Key: O(1) O(1) Best for high performance lookups.
SortedDictionary Sorted Via Key Key: O(log n) O(log n)
Compromise of Dictionary speed and
ordering, uses binary search tree.
List Unordered Via Index
Index: O(1)
Value: O(n)
O(n)
Best for smaller lists where direct
access required and no sorting.
SortedList Sorted Via Key Key: O(log n) O(n)
Faster lookup on preloaded data, but
slower loads.
LinkedList Unordered No Key: O(n) O(1)
Best for lists where inserting/deleting in
middle is common and no direct access
required.
HashSet Unordered Via Key Key: O(1) O(1)
Unique unordered collection, like a
Dictionary except key and value are
same object.
Make your Application as Parallel as
Necessary, But not More
Kind of Parallelism
Parallelism
✓ Running multiple threads in parallel
✓ .NET 4.0 provide “Task Parallel Library(TPL)” to
simplify parallelism
✓ But, Threads are expensive - context switch, lock
Asynchrony
✓ Without blocking the caller’s thread
✓ .NET 4.5 introduce async programming
Demo
Manage Memory Efficiently
GC as a Performance Problem
■ The .NET GC is non-deterministic
✓ Contributes unexpecteds, potentially very
long delays that destroy responsiveness.
✓ No way to anticipate the delay or react to
it.
There’s no GC if you don’t allocate.
Reducing allocation is key to
reducing GC costs.
Reducing Allocation
✓ Use value types
✓ Pool large objects (such as buffers)
✓ Avoid allocation large temporary objects
Use IDisposable
✓ Finalize is expensive.
✓ Dispose the object that is not needed.
✓ GC does not call Dispose() for you. It’s
your duty to call it.
Demo
Going Further
✓ Making .NET Application Faster
✓ Making .NET Application Even Faster
✓ IDisposable Best Practices for C# Developers
✓ Entity Framework Database Performance Anti-Pattern
✓ Measuring .NET Performance
✓ .NET Performance Optimization and Profiling with JetBrains
dotTrace
✓ http://geekswithblogs.
net/BlackRabbitCoder/archive/2011/06/16/c.net-
fundamentals-choosing-the-right-collection-class.aspx
✓ https://msdn.microsoft.com/en-us/library/dd460717(v=vs.
100).aspx
THANKS
Any questions?
You can find me at
✓ @mainul098
✓ mainul098@mail.com

Contenu connexe

Tendances

The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 ObservabilityKnoldus Inc.
 
Monitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaMonitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaLama K Banna
 
Oracle-DB: Performance Analysis with Panorama
Oracle-DB: Performance Analysis with PanoramaOracle-DB: Performance Analysis with Panorama
Oracle-DB: Performance Analysis with PanoramaPeter Ramm
 
Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLarry Cai
 
Schema-on-Read vs Schema-on-Write
Schema-on-Read vs Schema-on-WriteSchema-on-Read vs Schema-on-Write
Schema-on-Read vs Schema-on-WriteAmr Awadallah
 
What Is Hadoop | Hadoop Tutorial For Beginners | Edureka
What Is Hadoop | Hadoop Tutorial For Beginners | EdurekaWhat Is Hadoop | Hadoop Tutorial For Beginners | Edureka
What Is Hadoop | Hadoop Tutorial For Beginners | EdurekaEdureka!
 
JupyterHub: Learning at Scale
JupyterHub: Learning at ScaleJupyterHub: Learning at Scale
JupyterHub: Learning at ScaleCarol Willing
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresEDB
 
Introduction to HiveQL
Introduction to HiveQLIntroduction to HiveQL
Introduction to HiveQLkristinferrier
 
Spark introduction and architecture
Spark introduction and architectureSpark introduction and architecture
Spark introduction and architectureSohil Jain
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseenissoz
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbaseiammutex
 
SQL-on-Hadoop Tutorial
SQL-on-Hadoop TutorialSQL-on-Hadoop Tutorial
SQL-on-Hadoop TutorialDaniel Abadi
 

Tendances (20)

The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Druid+superset
Druid+supersetDruid+superset
Druid+superset
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 Observability
 
Monitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafaMonitoring &amp; alerting presentation sabin&amp;mustafa
Monitoring &amp; alerting presentation sabin&amp;mustafa
 
Oracle-DB: Performance Analysis with Panorama
Oracle-DB: Performance Analysis with PanoramaOracle-DB: Performance Analysis with Panorama
Oracle-DB: Performance Analysis with Panorama
 
Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Schema-on-Read vs Schema-on-Write
Schema-on-Read vs Schema-on-WriteSchema-on-Read vs Schema-on-Write
Schema-on-Read vs Schema-on-Write
 
What Is Hadoop | Hadoop Tutorial For Beginners | Edureka
What Is Hadoop | Hadoop Tutorial For Beginners | EdurekaWhat Is Hadoop | Hadoop Tutorial For Beginners | Edureka
What Is Hadoop | Hadoop Tutorial For Beginners | Edureka
 
JupyterHub: Learning at Scale
JupyterHub: Learning at ScaleJupyterHub: Learning at Scale
JupyterHub: Learning at Scale
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
Introduction to HiveQL
Introduction to HiveQLIntroduction to HiveQL
Introduction to HiveQL
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Spark introduction and architecture
Spark introduction and architectureSpark introduction and architecture
Spark introduction and architecture
 
HazelCast
HazelCastHazelCast
HazelCast
 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBase
 
Postgresql
PostgresqlPostgresql
Postgresql
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbase
 
SQL-on-Hadoop Tutorial
SQL-on-Hadoop TutorialSQL-on-Hadoop Tutorial
SQL-on-Hadoop Tutorial
 
Docker architecture-04-1
Docker architecture-04-1Docker architecture-04-1
Docker architecture-04-1
 

En vedette

.Net Performance by Bijoy Singhal
.Net Performance by Bijoy Singhal.Net Performance by Bijoy Singhal
.Net Performance by Bijoy SinghalRishu Mehra
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...Steve Lange
 
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...Steve Lange
 
Improving Performance in .NET Applications
Improving Performance in .NET ApplicationsImproving Performance in .NET Applications
Improving Performance in .NET Applicationsjasonbock
 
Building Scalable .NET Apps
Building Scalable .NET AppsBuilding Scalable .NET Apps
Building Scalable .NET AppsGuy Nirpaz
 
Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Yulia Tsisyk
 
How to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteHow to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteDNN
 
Building Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuilding Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuu Nguyen
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websitesoazabir
 
Four Practices to Fix Your Top .NET Performance Problems
Four Practices to Fix Your Top .NET Performance ProblemsFour Practices to Fix Your Top .NET Performance Problems
Four Practices to Fix Your Top .NET Performance ProblemsAndreas Grabner
 
Metrics Driven DevOps - Automate Scalability and Performance Into your Pipeline
Metrics Driven DevOps - Automate Scalability and Performance Into your PipelineMetrics Driven DevOps - Automate Scalability and Performance Into your Pipeline
Metrics Driven DevOps - Automate Scalability and Performance Into your PipelineAndreas Grabner
 

En vedette (11)

.Net Performance by Bijoy Singhal
.Net Performance by Bijoy Singhal.Net Performance by Bijoy Singhal
.Net Performance by Bijoy Singhal
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
 
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
 
Improving Performance in .NET Applications
Improving Performance in .NET ApplicationsImproving Performance in .NET Applications
Improving Performance in .NET Applications
 
Building Scalable .NET Apps
Building Scalable .NET AppsBuilding Scalable .NET Apps
Building Scalable .NET Apps
 
Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"
 
How to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteHow to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET Website
 
Building Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuilding Scalable .NET Web Applications
Building Scalable .NET Web Applications
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites
 
Four Practices to Fix Your Top .NET Performance Problems
Four Practices to Fix Your Top .NET Performance ProblemsFour Practices to Fix Your Top .NET Performance Problems
Four Practices to Fix Your Top .NET Performance Problems
 
Metrics Driven DevOps - Automate Scalability and Performance Into your Pipeline
Metrics Driven DevOps - Automate Scalability and Performance Into your PipelineMetrics Driven DevOps - Automate Scalability and Performance Into your Pipeline
Metrics Driven DevOps - Automate Scalability and Performance Into your Pipeline
 

Similaire à Performance Tuning of .NET Application

Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Gabriele Baldassarre
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceDavid Hoerster
 
Building a Testable Data Access Layer
Building a Testable Data Access LayerBuilding a Testable Data Access Layer
Building a Testable Data Access LayerTodd Anglin
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaDavid Chandler
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Ravi Okade
 
Perl and Elasticsearch
Perl and ElasticsearchPerl and Elasticsearch
Perl and ElasticsearchDean Hamstead
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Ssis Best Practices Israel Bi U Ser Group Itay Braun
Ssis Best Practices   Israel Bi U Ser Group   Itay BraunSsis Best Practices   Israel Bi U Ser Group   Itay Braun
Ssis Best Practices Israel Bi U Ser Group Itay Braunsqlserver.co.il
 
Secrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archsSecrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archsTarik Essawi
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databaseselliando dias
 
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017Jelastic Multi-Cloud PaaS
 
.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath CommunityRohit Radhakrishnan
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxRohit Radhakrishnan
 
Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Developmentelliando dias
 

Similaire à Performance Tuning of .NET Application (20)

Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
Talend Open Studio Fundamentals #1: Workspaces, Jobs, Metadata and Trips & Tr...
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data Persistence
 
Building a Testable Data Access Layer
Building a Testable Data Access LayerBuilding a Testable Data Access Layer
Building a Testable Data Access Layer
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for Java
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
 
Perl and Elasticsearch
Perl and ElasticsearchPerl and Elasticsearch
Perl and Elasticsearch
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Ssis Best Practices Israel Bi U Ser Group Itay Braun
Ssis Best Practices   Israel Bi U Ser Group   Itay BraunSsis Best Practices   Israel Bi U Ser Group   Itay Braun
Ssis Best Practices Israel Bi U Ser Group Itay Braun
 
Secrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archsSecrets of highly_avail_oltp_archs
Secrets of highly_avail_oltp_archs
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databases
 
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
 
JEEconf 2017
JEEconf 2017JEEconf 2017
JEEconf 2017
 
.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community.Net Classes and Objects | UiPath Community
.Net Classes and Objects | UiPath Community
 
Certification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptxCertification preparation - Net classses and functions.pptx
Certification preparation - Net classses and functions.pptx
 
Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Development
 

Performance Tuning of .NET Application

  • 1. Performance Tuning of .NET application Md. Mainul Islam Software Engineer, SELISE mainul098@mail.com
  • 2. ✓ What is Performance Tuning? ✓ How to profile performance? ✓ Identify hotspot bottlenecks ✓ Ways to optimize .NET Application. Why Are We Here?
  • 4. “Performance tuning is the improvement of system performance”
  • 5. Your app Reality of Performance You
  • 6. Where is the Bottleneck? for (int n = 2; n < 10000; ++n) { bool prime = true; for (int d = 2; d < n; ++d) { if (n % d == 0) { prime = false; break; } } if (prime) Console.WriteLine(n); }
  • 7. “Premature optimization is the root of all evil” - Donald Knuth
  • 8. Mistakes of Performance Tuning ✓ Optimize without a reliable measurement ✓ Optimize without verifying the results ✓ Relying on gut feeling
  • 9. Performance Matrices CPU Execution time, queuing Memory Utilization, load % Disk Utilization, I/O Operation Network Bandwidth, queueing
  • 10. How does it work? 1. Select Application to Profile 2. Start Profiling 3. Collect Data and Detect Bottlenecks 4. Optimize Performance 5. Compare Profiling Results 6. Repeat Until Desired Results (Or Possible)
  • 13. Dozens of Builtin Collections ✓ List<T> ✓ ArrayList<T> ✓ Dictionary<K,V> ✓ HashSet<T> ✓ Queue<T> ✓ SortedList<K,V> ✓ SortedDictionary<K,V> ✓ SortedSet<T> ✓ Stack<T> … and more
  • 14. Choose Proper Collection ■ Stop using List<T> for everything ■ Ask yourself: Do you need to access each element by index? For zero-based index: Use ArrayList and StringCollection classes and the List<T> generic class. For key based index: The Hashtable, SortedList, ListDictionary, and StringDictionary classes, and the Dictionary<TKey, TValue> and SortedDictionary<TKey, TValue> generic classes. Do you need to sort your collection? The Hashtable class sorts its elements by their hash codes. The SortedDictionary<TKey, TValue> and SortedList<TKey, TValue> generic classes sort their elements by the key.
  • 15. Collection - (Contd.) Do you need to search your collection? ListDictionary is faster than Hashtable for small collections (10 items or fewer). The Dictionary<TKey, TValue> generic class provides faster lookup than the SortedDictionary<TKey, TValue> generic class. The multi-threaded implementation is ConcurrentDictionary<TKey, TValue>. ConcurrentBag<T> provides fast multi-threaded insertion for unordered data. Do you need collections that accept only strings? StringCollection (based on IList) and StringDictionary (based on IDictionary).
  • 16. Collection Ordering Direct Access? Lookup Efficiency Manipulate Efficiency Notes Dictionary Unordered Via Key Key: O(1) O(1) Best for high performance lookups. SortedDictionary Sorted Via Key Key: O(log n) O(log n) Compromise of Dictionary speed and ordering, uses binary search tree. List Unordered Via Index Index: O(1) Value: O(n) O(n) Best for smaller lists where direct access required and no sorting. SortedList Sorted Via Key Key: O(log n) O(n) Faster lookup on preloaded data, but slower loads. LinkedList Unordered No Key: O(n) O(1) Best for lists where inserting/deleting in middle is common and no direct access required. HashSet Unordered Via Key Key: O(1) O(1) Unique unordered collection, like a Dictionary except key and value are same object.
  • 17. Make your Application as Parallel as Necessary, But not More
  • 18. Kind of Parallelism Parallelism ✓ Running multiple threads in parallel ✓ .NET 4.0 provide “Task Parallel Library(TPL)” to simplify parallelism ✓ But, Threads are expensive - context switch, lock Asynchrony ✓ Without blocking the caller’s thread ✓ .NET 4.5 introduce async programming
  • 19. Demo
  • 21. GC as a Performance Problem ■ The .NET GC is non-deterministic ✓ Contributes unexpecteds, potentially very long delays that destroy responsiveness. ✓ No way to anticipate the delay or react to it.
  • 22. There’s no GC if you don’t allocate. Reducing allocation is key to reducing GC costs.
  • 23. Reducing Allocation ✓ Use value types ✓ Pool large objects (such as buffers) ✓ Avoid allocation large temporary objects
  • 24. Use IDisposable ✓ Finalize is expensive. ✓ Dispose the object that is not needed. ✓ GC does not call Dispose() for you. It’s your duty to call it.
  • 25. Demo
  • 26. Going Further ✓ Making .NET Application Faster ✓ Making .NET Application Even Faster ✓ IDisposable Best Practices for C# Developers ✓ Entity Framework Database Performance Anti-Pattern ✓ Measuring .NET Performance ✓ .NET Performance Optimization and Profiling with JetBrains dotTrace ✓ http://geekswithblogs. net/BlackRabbitCoder/archive/2011/06/16/c.net- fundamentals-choosing-the-right-collection-class.aspx ✓ https://msdn.microsoft.com/en-us/library/dd460717(v=vs. 100).aspx
  • 27. THANKS Any questions? You can find me at ✓ @mainul098 ✓ mainul098@mail.com