Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Release build optimizations

Release build optimizations

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestionalgorithmsdata-structuresperformance
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Rohde
    wrote on last edited by
    #1

    Hi, I'm facing a weird issue on one of my applications on a customers machine. I cannot reproduce it on my machine but I'm trying to understand what might have happened according to the log. Basically the following code is executed:

    public override bool Modify(LabelProperties properties, object[] values)
    {
    try
    {
    if(values[0] == null)
    return false;

      int sourceIndex = Convert.ToInt32(((Key)values\[0\]).Value);
    
      //some other code but no further conversions			
    

    }
    catch (Exception exc)
    {
    _log.Error("Modify - " + exc.Message, exc);
    try
    {
    _log.Info("Key Value: " + ((Key)values[0]).Value);
    }
    catch {}
    return false;
    }
    return false;
    }

    The following information gets logged: 10:58:07 | Error | HiddenCategoryFeaturesLabelModifier::Modify - Die Eingabezeichenfolge hat das falsche Format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at DE.IVU.FilialInfo.Map.ThematicMaps.Modifiers.HiddenCategoryFeaturesLabelModifier.Modify(LabelProperties properties, Object[] values) Two things seem weird to me: 1. Although I'm using Convert.ToInt32 only System.Number.ParseInt32 is logged with the call stack. 2. The log call in the exception handler isn't done, which is weird because the first exception occurs in the number conversion routine. Thus I assume the cast and the property getter Value are working fine. But why aren't they within the handler? Basically my question is if this behavior can be explained with the optimizations happening in the optimized release build. Does optimization really replace higher level calls with lower level calls? (Just as a note: _log is a log4net.ILog instance and I assume it is working correctly. At least I didn't have any issues with it till now).

    T G 2 Replies Last reply
    0
    • R Robert Rohde

      Hi, I'm facing a weird issue on one of my applications on a customers machine. I cannot reproduce it on my machine but I'm trying to understand what might have happened according to the log. Basically the following code is executed:

      public override bool Modify(LabelProperties properties, object[] values)
      {
      try
      {
      if(values[0] == null)
      return false;

        int sourceIndex = Convert.ToInt32(((Key)values\[0\]).Value);
      
        //some other code but no further conversions			
      

      }
      catch (Exception exc)
      {
      _log.Error("Modify - " + exc.Message, exc);
      try
      {
      _log.Info("Key Value: " + ((Key)values[0]).Value);
      }
      catch {}
      return false;
      }
      return false;
      }

      The following information gets logged: 10:58:07 | Error | HiddenCategoryFeaturesLabelModifier::Modify - Die Eingabezeichenfolge hat das falsche Format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at DE.IVU.FilialInfo.Map.ThematicMaps.Modifiers.HiddenCategoryFeaturesLabelModifier.Modify(LabelProperties properties, Object[] values) Two things seem weird to me: 1. Although I'm using Convert.ToInt32 only System.Number.ParseInt32 is logged with the call stack. 2. The log call in the exception handler isn't done, which is weird because the first exception occurs in the number conversion routine. Thus I assume the cast and the property getter Value are working fine. But why aren't they within the handler? Basically my question is if this behavior can be explained with the optimizations happening in the optimized release build. Does optimization really replace higher level calls with lower level calls? (Just as a note: _log is a log4net.ILog instance and I assume it is working correctly. At least I didn't have any issues with it till now).

      T Offline
      T Offline
      Tim Paaschen
      wrote on last edited by
      #2

      Hi, 1. Although I'm using Convert.ToInt32 only System.Number.ParseInt32 is logged with the call stack. As far as I know, Convert.ToInt32 does a check for null parameters and then passes the parameter to lower level methods. However, I still would have expected to see Convert.ToInt32 in the stack trace. 2. The log call in the exception handler isn't done, which is weird because the first exception occurs in the number conversion routine. Thus I assume the cast and the property getter Value are working fine. But why aren't they within the handler? The _log.Error call is done, therefore I assume the _log.Info call is done, too. What filters do you have applied to the log? I typically set the log4net filter level to WARN or ERROR in release versions.

      Regards, Tim

      R 1 Reply Last reply
      0
      • T Tim Paaschen

        Hi, 1. Although I'm using Convert.ToInt32 only System.Number.ParseInt32 is logged with the call stack. As far as I know, Convert.ToInt32 does a check for null parameters and then passes the parameter to lower level methods. However, I still would have expected to see Convert.ToInt32 in the stack trace. 2. The log call in the exception handler isn't done, which is weird because the first exception occurs in the number conversion routine. Thus I assume the cast and the property getter Value are working fine. But why aren't they within the handler? The _log.Error call is done, therefore I assume the _log.Info call is done, too. What filters do you have applied to the log? I typically set the log4net filter level to WARN or ERROR in release versions.

        Regards, Tim

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        I'm logging all levels. To be sure I just made a quick check and saw many other log entries of type Info (even coming from the same logger instance) but this one is missing.

        1 Reply Last reply
        0
        • R Robert Rohde

          Hi, I'm facing a weird issue on one of my applications on a customers machine. I cannot reproduce it on my machine but I'm trying to understand what might have happened according to the log. Basically the following code is executed:

          public override bool Modify(LabelProperties properties, object[] values)
          {
          try
          {
          if(values[0] == null)
          return false;

            int sourceIndex = Convert.ToInt32(((Key)values\[0\]).Value);
          
            //some other code but no further conversions			
          

          }
          catch (Exception exc)
          {
          _log.Error("Modify - " + exc.Message, exc);
          try
          {
          _log.Info("Key Value: " + ((Key)values[0]).Value);
          }
          catch {}
          return false;
          }
          return false;
          }

          The following information gets logged: 10:58:07 | Error | HiddenCategoryFeaturesLabelModifier::Modify - Die Eingabezeichenfolge hat das falsche Format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at DE.IVU.FilialInfo.Map.ThematicMaps.Modifiers.HiddenCategoryFeaturesLabelModifier.Modify(LabelProperties properties, Object[] values) Two things seem weird to me: 1. Although I'm using Convert.ToInt32 only System.Number.ParseInt32 is logged with the call stack. 2. The log call in the exception handler isn't done, which is weird because the first exception occurs in the number conversion routine. Thus I assume the cast and the property getter Value are working fine. But why aren't they within the handler? Basically my question is if this behavior can be explained with the optimizations happening in the optimized release build. Does optimization really replace higher level calls with lower level calls? (Just as a note: _log is a log4net.ILog instance and I assume it is working correctly. At least I didn't have any issues with it till now).

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The Convert.ToInt32(string) method just checks for a null value, then calls Int32.Parse. It's quite possible that this code is inlined by the compiler. The inlined code would in that case resemble:

          string temp = ((Key)values[0]).Value;
          int sourceIndex = (temp == null) ? 0 : Int32.Parse(temp, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);

          --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups