Skip to content

Skip calling dotnet --info by using --list-x --arch when available #2296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 5, 2025

Conversation

nagilson
Copy link
Member

@nagilson nagilson commented Jun 2, 2025

dotnet --info resolves in the sdk (C# code) instead of the host (C++) code. It also resolves workloads and a slew of other JIT-ed components which makes it very 'slow' in comparison to host commands.

We only call --info to get the architecture of an existing install. Thus, after some discussion in my issue here: dotnet/runtime#108503, the runtime team dotnet/runtime#116078 added support for dotnet --list-runtimes --arch and the same for --list-sdks.

What this flag does is show the installs that match the specified architecture given in arch.
The previous behavior ignored other flags and also only printed what matched the host architecture (unknown, which is what we got from info.)

I've utilized this new API to improve performance by skipping dotnet --info when applicable. We still need to call it for some .NET hosts before the .NET 10 hosts that have this functionality. And the easiest way to check is by seeing if --arch invalid fails or not (in which case, it supports --arch.) This is somewhat unfortunate as it is slower, but the best we came up with. (See discussion in the aforementioned PR.) I added some rudimentary logic to skip this --arch support check, if the host is already known to be too old (e.g. younger than .NET 10) to prevent this from slowing down the existing scenario too much (most people are on .NET 8.) I also time-gated it to always check after a certain point, as mentioned in the comments. Somewhat hacky, but probably sufficient.

nagilson added 3 commits May 29, 2025 17:19
 dotnet/runtime#116078 --arch was not added until .NET 10 to allow us to skip calling dotnet --info because that is slow, as it is not native code.
        // However, --arch gets ignored if the host does not support it. The output is also identical with or without --arch.
        // After discussion with the runtime team, the best way to determine if the host supports --arch is to call it with an invalid arch to see if it fails, because that only happens when --arch is supported.

        // The --arch flag was added in the middle of .NET 10, so we can assume it is supported if the version is 10.0 or later.
        // We don't want to slow down the current common case for people without .NET 10 by adding another process spawn check.
        // We don't check that the version is 10.0 or later after 2026 when .NET 11 starts rolling out, as It will be slower to check all of the numbers in the output for versions >= 10.
Also support .NET 11 behavior while its in pre-release
@nagilson nagilson marked this pull request as ready for review June 2, 2025 21:34
@nagilson nagilson requested a review from a team June 3, 2025 18:09
Comment on lines +156 to +158
// https://github.com/dotnet/runtime/pull/116078 --arch was not added until .NET 10 to allow us to skip calling dotnet --info because that is slow, as it is not native code.
// However, --arch gets ignored if the host does not support it. The output is also identical with or without --arch.
// After discussion with the runtime team, the best way to determine if the host supports --arch is to call it with an invalid arch to see if it fails, because that only happens when --arch is supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of an aloud note to myself, but it is obviously a problem that we have no clear delineation between native-based and non-native-based CLI operations. And the other problem is that the perf between those is so vastly different. I know AOT was discussed, but there must be a non-AOT solution and a solution that doesn't require pushing more functionality into the host itself (native code). 🤔

@nagilson nagilson merged commit 9d40cb6 into dotnet:main Jun 5, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants