HACKER Q&A
📣 sandreas

C# reloadOnChange=true slows down startup on Linux by 2.2 seconds. Why?


I asked this question on stackoverflow, but nobody seems to have an answer yet. Maybe you guys could help. Using the configBuilder with reloadOnChange=true leads to a HUGE slowdown in startup time (usually >1000% - in bigger apps 10 seconds and more). It is dotnet 6 with release mode producing a single executable binary...

The line that matters is:

  configBuilder.AddJsonFile(f, true, true); 
Here is the full code:

  var configBuilder = new ConfigurationBuilder();
  
  var configFiles = new[]
  {
      Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"),
      // the files below do not exist, not even the directory - just a fallback
      Path.Combine(Environment.GetFolderPath(UserProfile, DoNotVerify), ".tester/appsettings.json"),
      Path.Combine(Environment.GetFolderPath(ApplicationData, DoNotVerify), "tester/appsettings.json"),
  };
  
  foreach (var f in configFiles)
  {
      // using the line below works fast like expected
      // configBuilder.AddJsonFile(f, true, false); 
      
      // HUGE slowdown of app startup with second parameter set to true. Why?
      configBuilder.AddJsonFile(f, true, true); 
  }
  
  var config = configBuilder.Build();
  Console.WriteLine("tester");

More details: https://stackoverflow.com/questions/71179452/c-sharp-configurationbuilder-with-reloadonchange-true-slows-down-app-startup-on


  👤 db48x Accepted Answer ✓
The usual answer to this type of question is to strace your program to get an idea of where it is spending all of that time. All the other details are irrelevant; the answer is always to measure the performance.

👤 amir734jj
I will start a bounty for it on Stack Overflow as soon as it becomes eligible