The #1 Rule for .NET Performance

If you ask me one tip to improve the performance of your applications, it would be:

Design your objects to be collected on gen #0
or not at all.

Naturally, following this recommendation demands you to know, at least the basics, of how the garbage collection works. But, if you are interested in improving the performance of your applications, this is necessary at all.

In fact, the garbage collector was explicitly designed to be very efficient performing gen #0.

Garbage collector gets more expensive in each generation. Even with background processing for gen #2, there is still a very high CPU cost to pay. Consider that you should avoid gen #1 collections too. In most scenarios, gen #1 objects are directly promoted to gen #2.

Ideally, every object you allocate goes out of scope by the time next gen #0 comes around. You can measure how long is that interval and compare it to the duration that data is alive in your application using tools such as PerfView (By the way, take some time and learn how to use PerfView – this is such great tool).

Time to action

Following this recommendation requires a shift in your mindset. It will inform nearly every aspect of your application (I strongly recommend you this Ayende’s talk about this topic).

Here are some guidelines to keep in mind when writing your code:

Isn’t that enough? In the next weeks, I will share in-depth information about how you could follow these recommendations to get improved .NET applications performance. Sign in my contacts list, and you will receive notification when new content arrives.

Last but not least, remember that [tweet]Performance is a feature. If the performance of your application is not that good, chances are you missing opportunities to deliver business value.[/tweet]

Cover image: chuttersnap

Compartilhe este insight:

3 respostas

  1. Elemar, existe alguma ferramenta que permita esse monitoramento de performance?
    Digo, aplicando algumas melhorias mencionadas por você, como posso avaliar se realmente surtiram efeito?

    Grande abraço e obrigado por compartilhar suas experiências.

    1. The question was about tools. Let’s go: PerfMon, Visual Studio, dotTrace, windbg, BenchmarkDotNet, NPerf … 🙂 Your watch

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Mais insights para o seu negócio

Veja mais alguns estudos e reflexões que podem gerar alguns insights para o seu negócio:

A EximiaCo não vende! Quando planejei a empresa decidi que ela não teria um departamento comercial. A estratégia é buscar...
[tweet]Aprenda comigo técnicas de modelagem de bancos de dados de documentos NoSQL e a utilizar o RavenDB[/tweet] – um dos...
To write parallel code is not a trivial task. There are details to consider and rules to observe. Could you...
O ano era 2001 ou 2002. Não lembro ao certo. Eu era um jovem programador, pai recente, tentando “encontrar meu...
Neste post, apresento o conceito de “Dívida Técnica” (não é débito, é dívida). Explico por que nem sempre elas são...
Nossos códigos precisam ser fáceis de compilar e testar. Para isso, nada melhor do que começarmos da forma certa, com...
× Precisa de ajuda?