52 Tips & Tricks to Boost .NET Performance.pdf

(1657 KB) Pobierz
1
This is a .NET community generated
eBook with contributions from .NET
experts everywhere
SRINIVASU ACHALLA
BARTOSZ ADAMCZEWSKI
DAVID BERRY
GIORGI DALAKISHVILI
JONATHAN DANYLKO
RAKESH NHALIL EDAVALATH
BEN EMMETT
SHUBHAJYOTI GHOSH
PAUL GLAVICH
NICK HARRISON
ZIJIAN HUANG
ROB KARATZAS
ANDRE KRAEMER
2
GAVIN LANATA
MEGHA MAHESHWARI
NIK MOLNAR
COSIMO NOBILE
JEFF OSIA
RAGHAVENDRA RENTALA
RICHIE RUMP
LOUIS SOMERS
MICHAEL SORENS
RAINER STROPEK
TUGBERK UGURLU
MATT WARREN
GREG YOUNG
What do you do
when you have a
.NET problem?
Your code is running slow. There’s too much load on your database.
Memory usage is causing performance problems.
You get the picture.
One solution is to sit back and ask the advice of fellow .NET experts.
Developers who have had exactly the same problem at some point and
spent hours finding the right solution.
That’s what we did. We asked .NET developers everywhere for their tips
on how to make .NET perform smarter, faster, and better.
And this eBook is the result.
All that knowledge distilled into an easily digestible form so that rather
than taking hours to find the answer you need, it will take just seconds.
Thanks to the .NET community for contributing so many valuable tips.
Thanks too to Paul Glavich and Ben Emmett who edited them.
Now it’s over to you.
Enjoy the tips – and if you slave for hours over a problem we’ve not
covered and come up with a beautifully elegant solution, let us know.
We’ll save it for the next book.
Carly Meichen
dotnetteam@red-gate.com
Contents
Tips 1-6
General performance advice
Tips 7-17
.NET performance
improvements
Tips 18-26
ASP.NET
Tips 27-40
Database access
Tips 41-47
Memory usage
Tips 48-52
General hints
4
5
10
20
28
44
51
GENERAL PEFORMANCE
ADVICE
1
If you must measure small time
differences in your code, ensure you use
the StopWatch class
Giorgi Dalakishvili
@GioDalakishvili
www.aboutmycode.com
DateTime.UtcNow isn’t designed for high-precision timing and
will often have a resolution over 10ms, making it unsuitable
for measuring small periods of time. The StopWatch class is
designed for this purpose, although beware of ending up with
an entire codebase with StopWatch instrumentation.
2
Fully utilize all bottlenecks
Louis Somers
@infotopie
www.infotopie.nl/blog
While Async-Await habits work well, an architectural pattern
can switch into higher gears. When processing multiple small
jobs, consider splitting job parts into resource-specific chunks.
Then create separate threads for each resource, and place
memory buffers in between. The goal is to fully utilize whatever
resource is the bottleneck on any given machine.
5
Zgłoś jeśli naruszono regulamin