5 ms·
Ask HN: 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
- amir734jj 5y agoI will start a bounty for it on Stack Overflow as soon as it becomes eligible
- db48x 5y agoThe 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.
- sandreas 5y agoWell, that is absolutely correct. Thanks for this hint, I'll try my best to do so and answer my own question. I just thought this is an interesting problem to others.
- db48x 5y ago> I just thought this is an interesting problem to others. Frankly I doubt that it is. I bet the number of people who have encountered this problem is quite small: most developers don’t use C#, of those most of them have not written code that uses this ConfigurationBuilder thing, and most of those probably never noticed any problems. There might only be a dozen people in the world who have had a similar problem! It could even be unique to your hardware, or your software configuration, or even to a pattern of behavior. The problem with asking this kind of question is that you are looking for someone with deep expertise or who has already encountered exactly the same pitfall as you. Instead of asking for a solution, it would be better to ask how to _find_ a solution. There are more people who can answer such questions!
- sandreas 5y agoThanks... makes sense to me. Maybe i will contribute by finding a solution and describing the way to get there.