Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
Are parameters of conditional methods (Debug.Assert(...)) optimized away in release mode?

I often have expensive linq queries embedded in Debug.Assert().

Ex: Debug.Assert(!orderShipmentStatusLogs.GroupBy(c => new { c.Id, c.StartDateTime }).Any(c => c.Count() > 1));

In this case orderShipmentStatusLogs can be a huge list - so this code may be slow.

For performance i'm asking myself whether that's smart or not, i know the Debug.Assert() method gets removed in release mode, but from reading the docs:

Any arguments passed to the method or attribute are still type-checked by the compiler. https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-6.0

I'm a bit doubtfull.

So am I safe here or am i accidently slowing my app down by adding in heavy assertions? Is the parameter to Debug.Assert() optimized away?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The entire Debug.Assert line is optimised away when you build in Release mode. So:

Console.WriteLine("Before");
Debug.Assert(false);
Console.WriteLine("After");

Becomes:

Console.WriteLine("Before");
Console.WriteLine("After");

You can see this using SharpLab. In Debug mode the Assert is still there but in Release it is gone.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda