dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.88k stars 4.63k forks source link

Dev/Debug mode experience #104424

Open rmannibucau opened 2 months ago

rmannibucau commented 2 months ago

Hi,

I understand that debug mode adds a lot of helpers/tools during debugging but the experience is really bad compared to the standard run mode (a simple example is to run concurrently 10kthreads and see the time it takes to reach the 10k).

I think there could be a default in between mode where the debug additions are not enabled until used.

The goal is to have a debug experience which is close in terms of behavior/perf to the release mode but be able to enable more advanced features when needed (for example is a breakpoint is reached, the thread stack become available but if not all the threading debugging is not enabled except if some toggle - env var for ex - is set).

The test I did (10kthreads) makes it looking like the new Thread(...).Start() are throttled - in create_thread - in debug mode (tested in vscode) whereas it is not visible in standard run mode.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.

huoyaoyuan commented 2 months ago

in debug mode (tested in vscode)

It's because when the debugger is attached, it continuously interacts with the application to collect traces and handle events.

If you launch in Debug mode without attaching debugger, for example launching via console, you might see very different performance.

be able to enable more advanced features when needed

It's actually up to the debugger. When the debugger is attached, it's already enabling some features.

rmannibucau commented 2 months ago

@huoyaoyuan yes, I have to admit I'm not sure the issue is in vscode (for my case) or what the runtime provides in terms of what can be enabled/disabled but I didn't find how to tune the debugger to collect less by default, this is why I reported there but if it is there we can close this issue.

mikelle-rogers commented 1 month ago

Possible duplicate to https://github.com/dotnet/runtime/issues/38736, which was fixed for .NET 9 preview 5. @rmannibucau, would you please install .NET 9 preview 5 and see if the problem persists? Here is the website to install .NET 9: https://dotnet.microsoft.com/en-us/download/dotnet/9.0

rmannibucau commented 1 month ago

Hi @mikelle-rogers , tested 9.0.0-preview.6.24327.7 and runs just hang - on the Start() line, here is my main:

var watcher = new Stopwatch();
watcher.Start();
var all = new Thread[10_000];
for (int i = 0; i < all.Length; i++)
{
    all[i] = new Thread(() => { });
    all[i].Start();
}
for (int i = 0; i < all.Length; i++)
{
    all[i].Join();
}
watcher.Stop();
Console.WriteLine($"done in {watcher.ElapsedMilliseconds}ms");

I'm still on linux (latest ubuntu) using vscode (from snap).

tommcdon commented 1 month ago

This may also be related to https://github.com/dotnet/runtime/issues/11466

rmannibucau commented 1 month ago

Just let me know if I can test a preview again in the coming week (then it will be holidays there ;)).

mikelle-rogers commented 1 month ago

Thank you for sending in this suggestion! After careful consideration, we do not plan to action this particular item in this release. We will continue to evaluate it for future releases. Ideally, we would like to fix every issue and implement every idea people submit. Realistically, we cannot address every item.