SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Performance Best Practices – Part 2 –
Server Side [.NET, C#, MVC, LINQ, EF]

Presenter: Sathyan, Mindfire Solutions
Date: 08th Oct 2013





Use Using statements wherever possible
Avoid Exceptions –NULL reference exception
- Be safe! Make Use of TryParse Etc! Also even
when you use TryParse remember that it will
handle just an ArgumentException and Not all
types!
After avoiding as much as possible, expect &
handle Exceptions, even though there are
some who argue that Exception Handling is
costly, No, it is not an option not to have it at
all!
Presenter: Sathyan, Mindfire Solutions








control application flow based on exceptions?
It is just not try – catch; let us not forget
finally! Also remember try-finally
It is better not to throw!
When you catch an exception, creating an
object and then throwing will alter stacktrace,
not a best thing to have when we want to
track and shoot down exceptions
Never suppress exceptions – Empty Catch
blocks; they serve NO purpose!
Presenter: Sathyan, Mindfire Solutions





Dispose objects, Yes, this is indeed a
debatable point but let us be safer than sorry!
It is always safer to call Close or Dispose for
supported objects rather than not doing it;
implement IDisposable!
Acquire late, release early
Declare as close as to usage as possible –
don’t do this when you have a really huge
loop, better to declare outside!

Presenter: Sathyan, Mindfire Solutions








If we need to get 10 items, it is always
preferable to get all 10 together rather than
connecting/fetching 10 times!
Reuse code as much as possible. DRY! Don’t
Repeat Yourself! Just Do It
Avoid locks & synchronization as much as
possible, use only when it is justified and
when you are a Master of the Game
Consider using Task Factory – Parallel
processing for heavy processing loops –
Presenter: Sathyan, Mindfire Solutions






Boxing (and unboxing) is best left to stages

and competitions, avoid as much as possible.
This is where Generics help, before Generics
we were left with only Objects, which would
make the CLR to box unbox internally so
many thousands of times in each application,
each day!
Firing queries inside loop is bad and should
be avoided, as much as possible get all
necessary data in the outer query
Use String Builder over Concat when you need
to append more than 6 or 7 string instances
Presenter: Sathyan, Mindfire Solutions






Be aware that comparing unconstrained type
parameter values against Null is extremely
slow for nullable value types
Always return only what is necessary
With fields of type derived from
MarshalByRefObject, the performance is
particularly bad because the CLR really ends
up calling methods to perform the field
access.

Presenter: Sathyan, Mindfire Solutions






We all know that reflection is bad, so please
use it only it is absolutely needed like
creation of all new dynamic runtime forms
Etc.
ASP.NET DataBinder.Eval is to be avoided – it
uses reflection internally
Virtual methods are great but come with a
performance overload, so seal your classes
whenever possible and when you don’t mean
to inherit them anymore!
Presenter: Sathyan, Mindfire Solutions




Stack<T> for a LIFO; Queue<T> for a FIFO;
List<T> for random access with zero based

indexing; if no duplicates in the collection,
always use HashSet<T> - that is the fastest
of the lot; Dictionary<TKey,List<TValue>>
over List <KeyValuePair<TKey,TValue>> for
O-M - Lookup speed will be much faster and
client code will be less clumsy.
Link: http://www.packtpub.com/article/.netgenerics-40-container-patterns-bestpractices
Presenter: Sathyan, Mindfire Solutions








Prefer LINQ Standard Query Operator Where()
over Contains(), Exists(), or Find() methods to
check whether a value is present in a List<T>
instance.
Use the OrderBy() or
the OrderByDescending() method to sort
any IEnumerable<T>
Avoid using of AsEnumerable() as it processes
on memory rather than on DB.
Prefer Query Syntax over looping! Looping is
heavy in any programming language!
Presenter: Sathyan, Mindfire Solutions










Session State
View State – Disable/Store In Server Example
Shown
Round Trips
Pagination
Pooling
Choose Your controls
Debug in Live Code? Trace?

Presenter: Sathyan, Mindfire Solutions










Cache – Output Cache(Browser, kernel, Proxy)
Control caching
Per-Request Caching – HttpContext
Fixed Connection string and a consistent
service account
Pool!
Return Only what you need
Exception Handling

Presenter: Sathyan, Mindfire Solutions










Heap Objects – CLR Profiler
OrdinalIgnoreCase – String Compare
Multiple Inserts at one Go
Grids
Client side applications
Log?
startMode – IIS – First Request – precompile
.NET 4.5 AysnchConstructs

Presenter: Sathyan, Mindfire Solutions







Parameterized Calls
Page.IsPostBack
Loops
Client Side Validations
Asynch Calls
Refactor

Presenter: Sathyan, Mindfire Solutions










ADO - DataReader Vs DataSet
Multiple ResultSets Reader.NextResult()
Command Type
Execute Scalar Execute NonQuery
DataReader CommandBehavior.CloseConnection
DataReader - SchemaOnly
DataSets – PrimaryKeys, Rows.Find

Presenter: Sathyan, Mindfire Solutions










Set Sessionstate to read only when you do not
write anything on services, controllers, Even
WCF Etc.
Stateless controllers
Use the AjaxRender Helper class [which is a
rendering engine] wherever applicable to
allow Asynch loading
Synchronous and Asynchronous pipelines in
MVC and make sure to use the appropriate
one at appropriate place
Use Html.ActionLink - Avoid Broken Links
Presenter: Sathyan, Mindfire Solutions


Use only the View Engines that you need

protected void Application_Start() {
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine()); }





Uninstall URL Rewrite if you don’t use it
Avoid passing null models to views
Remove unused HTTP Modules


Presenter: Sathyan, Mindfire Solutions






Explicitly tell EF the type of the expected
result wherever possible to avoid pulling all
possible derived types
When you want to retrieve a single entity
using entity key can be more efficient than
using WHERE clause [use of GetObjectByKey()
method]
To efficiently retrieve entities that will only
display and not update, use the
MergeOption.NoTracking merge option
Presenter: Sathyan, Mindfire Solutions






Avoid “let” http://msdn.microsoft.com/enus/library/bb383976.aspx in your queries as
much as possible
Consider using Compiled Queries –
CompileQuery.Compile() [note that this
decreases readability] – EF5 – Auto Compiled
ALWAYS see the actual SQL generated – you
will have many surprises here, you can use
LINQPad or MiniProfiler-EF or simply the trace
form SQL –
Presenter: Sathyan, Mindfire Solutions









I would personally advise SPs for anything
complex [though opinion is divided here]
Limit the scope of the ObjectContext
Once again, get ONLY the records that you
need!
SQL doesn’t care about CASE so do not
bother about using ToLower() Etc in your
LINQtoSQL
“for” is the fastest way of iterating over a
collection, foreach is a little slower, and LINQ
queries are slowest
Presenter: Sathyan, Mindfire Solutions






Glimpse
Mini Profiler
ANTS
NewRelic
NDepend

Presenter: Sathyan, Mindfire Solutions
Performance Best Practices - Part 2 - Server Side

Weitere ähnliche Inhalte

Andere mochten auch

Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsSarvesh Kushwaha
 
Human Resource Management System Java Project
Human Resource Management System Java ProjectHuman Resource Management System Java Project
Human Resource Management System Java ProjectTutorial Learners
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
3263270 human-resource-management-systems-hrms
3263270 human-resource-management-systems-hrms3263270 human-resource-management-systems-hrms
3263270 human-resource-management-systems-hrmschetanmbhimewal
 
Human Resource Management System (HRMS)
Human Resource Management System (HRMS)Human Resource Management System (HRMS)
Human Resource Management System (HRMS)Samaresh Debbarma
 
Overview of human resource management system & function
Overview of human resource management  system & functionOverview of human resource management  system & function
Overview of human resource management system & functionRita Choudhary
 
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
 

Andere mochten auch (10)

Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Human Resource Management System Java Project
Human Resource Management System Java ProjectHuman Resource Management System Java Project
Human Resource Management System Java Project
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
System approach to hrm
System approach to hrmSystem approach to hrm
System approach to hrm
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
3263270 human-resource-management-systems-hrms
3263270 human-resource-management-systems-hrms3263270 human-resource-management-systems-hrms
3263270 human-resource-management-systems-hrms
 
Unilever HRM case study
Unilever HRM case studyUnilever HRM case study
Unilever HRM case study
 
Human Resource Management System (HRMS)
Human Resource Management System (HRMS)Human Resource Management System (HRMS)
Human Resource Management System (HRMS)
 
Overview of human resource management system & function
Overview of human resource management  system & functionOverview of human resource management  system & function
Overview of human resource management system & function
 
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
 

Mehr von Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Kürzlich hochgeladen

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Performance Best Practices - Part 2 - Server Side

  • 1. Performance Best Practices – Part 2 – Server Side [.NET, C#, MVC, LINQ, EF] Presenter: Sathyan, Mindfire Solutions Date: 08th Oct 2013
  • 2.    Use Using statements wherever possible Avoid Exceptions –NULL reference exception - Be safe! Make Use of TryParse Etc! Also even when you use TryParse remember that it will handle just an ArgumentException and Not all types! After avoiding as much as possible, expect & handle Exceptions, even though there are some who argue that Exception Handling is costly, No, it is not an option not to have it at all! Presenter: Sathyan, Mindfire Solutions
  • 3.      control application flow based on exceptions? It is just not try – catch; let us not forget finally! Also remember try-finally It is better not to throw! When you catch an exception, creating an object and then throwing will alter stacktrace, not a best thing to have when we want to track and shoot down exceptions Never suppress exceptions – Empty Catch blocks; they serve NO purpose! Presenter: Sathyan, Mindfire Solutions
  • 4.    Dispose objects, Yes, this is indeed a debatable point but let us be safer than sorry! It is always safer to call Close or Dispose for supported objects rather than not doing it; implement IDisposable! Acquire late, release early Declare as close as to usage as possible – don’t do this when you have a really huge loop, better to declare outside! Presenter: Sathyan, Mindfire Solutions
  • 5.     If we need to get 10 items, it is always preferable to get all 10 together rather than connecting/fetching 10 times! Reuse code as much as possible. DRY! Don’t Repeat Yourself! Just Do It Avoid locks & synchronization as much as possible, use only when it is justified and when you are a Master of the Game Consider using Task Factory – Parallel processing for heavy processing loops – Presenter: Sathyan, Mindfire Solutions
  • 6.    Boxing (and unboxing) is best left to stages and competitions, avoid as much as possible. This is where Generics help, before Generics we were left with only Objects, which would make the CLR to box unbox internally so many thousands of times in each application, each day! Firing queries inside loop is bad and should be avoided, as much as possible get all necessary data in the outer query Use String Builder over Concat when you need to append more than 6 or 7 string instances Presenter: Sathyan, Mindfire Solutions
  • 7.    Be aware that comparing unconstrained type parameter values against Null is extremely slow for nullable value types Always return only what is necessary With fields of type derived from MarshalByRefObject, the performance is particularly bad because the CLR really ends up calling methods to perform the field access. Presenter: Sathyan, Mindfire Solutions
  • 8.    We all know that reflection is bad, so please use it only it is absolutely needed like creation of all new dynamic runtime forms Etc. ASP.NET DataBinder.Eval is to be avoided – it uses reflection internally Virtual methods are great but come with a performance overload, so seal your classes whenever possible and when you don’t mean to inherit them anymore! Presenter: Sathyan, Mindfire Solutions
  • 9.   Stack<T> for a LIFO; Queue<T> for a FIFO; List<T> for random access with zero based indexing; if no duplicates in the collection, always use HashSet<T> - that is the fastest of the lot; Dictionary<TKey,List<TValue>> over List <KeyValuePair<TKey,TValue>> for O-M - Lookup speed will be much faster and client code will be less clumsy. Link: http://www.packtpub.com/article/.netgenerics-40-container-patterns-bestpractices Presenter: Sathyan, Mindfire Solutions
  • 10.     Prefer LINQ Standard Query Operator Where() over Contains(), Exists(), or Find() methods to check whether a value is present in a List<T> instance. Use the OrderBy() or the OrderByDescending() method to sort any IEnumerable<T> Avoid using of AsEnumerable() as it processes on memory rather than on DB. Prefer Query Syntax over looping! Looping is heavy in any programming language! Presenter: Sathyan, Mindfire Solutions
  • 11.        Session State View State – Disable/Store In Server Example Shown Round Trips Pagination Pooling Choose Your controls Debug in Live Code? Trace? Presenter: Sathyan, Mindfire Solutions
  • 12.        Cache – Output Cache(Browser, kernel, Proxy) Control caching Per-Request Caching – HttpContext Fixed Connection string and a consistent service account Pool! Return Only what you need Exception Handling Presenter: Sathyan, Mindfire Solutions
  • 13.         Heap Objects – CLR Profiler OrdinalIgnoreCase – String Compare Multiple Inserts at one Go Grids Client side applications Log? startMode – IIS – First Request – precompile .NET 4.5 AysnchConstructs Presenter: Sathyan, Mindfire Solutions
  • 14.       Parameterized Calls Page.IsPostBack Loops Client Side Validations Asynch Calls Refactor Presenter: Sathyan, Mindfire Solutions
  • 15.        ADO - DataReader Vs DataSet Multiple ResultSets Reader.NextResult() Command Type Execute Scalar Execute NonQuery DataReader CommandBehavior.CloseConnection DataReader - SchemaOnly DataSets – PrimaryKeys, Rows.Find Presenter: Sathyan, Mindfire Solutions
  • 16.      Set Sessionstate to read only when you do not write anything on services, controllers, Even WCF Etc. Stateless controllers Use the AjaxRender Helper class [which is a rendering engine] wherever applicable to allow Asynch loading Synchronous and Asynchronous pipelines in MVC and make sure to use the appropriate one at appropriate place Use Html.ActionLink - Avoid Broken Links Presenter: Sathyan, Mindfire Solutions
  • 17.  Use only the View Engines that you need protected void Application_Start() { ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); }    Uninstall URL Rewrite if you don’t use it Avoid passing null models to views Remove unused HTTP Modules  Presenter: Sathyan, Mindfire Solutions
  • 18.    Explicitly tell EF the type of the expected result wherever possible to avoid pulling all possible derived types When you want to retrieve a single entity using entity key can be more efficient than using WHERE clause [use of GetObjectByKey() method] To efficiently retrieve entities that will only display and not update, use the MergeOption.NoTracking merge option Presenter: Sathyan, Mindfire Solutions
  • 19.    Avoid “let” http://msdn.microsoft.com/enus/library/bb383976.aspx in your queries as much as possible Consider using Compiled Queries – CompileQuery.Compile() [note that this decreases readability] – EF5 – Auto Compiled ALWAYS see the actual SQL generated – you will have many surprises here, you can use LINQPad or MiniProfiler-EF or simply the trace form SQL – Presenter: Sathyan, Mindfire Solutions
  • 20.      I would personally advise SPs for anything complex [though opinion is divided here] Limit the scope of the ObjectContext Once again, get ONLY the records that you need! SQL doesn’t care about CASE so do not bother about using ToLower() Etc in your LINQtoSQL “for” is the fastest way of iterating over a collection, foreach is a little slower, and LINQ queries are slowest Presenter: Sathyan, Mindfire Solutions