Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda