-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Avoid creating external processes to read OS version info #1240
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Since .NET 5 we can now use the `Environment.OSVersion` property to lookup the real OS version for macOS and Windows[1]. For .NET Framework (still used for our releases on Windows) we must continue to use the Win32 API `RtlGetVersion` to avoid any Windows compatibility nonsense. We continue to use `uname` on Linux. [1] https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/environment-osversion-returns-correct-version
mjcheetham
force-pushed
the
perf2
branch
2 times, most recently
from
May 4, 2023 15:39
a5e3f4a
to
b7aeb3a
Compare
ldennington
approved these changes
May 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
return swvers.StandardOutput.ReadToEnd().Trim(); | ||
} | ||
} | ||
return Environment.OSVersion.VersionString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Try using the /etc/os-release file, for systemd distros, in favour of calling out to `uname` which can add extra overhead in the form of process startup. Direct file I/O and parsing should be faster.
vdye
approved these changes
May 4, 2023
Merged
mjcheetham
added a commit
that referenced
this pull request
Jun 26, 2023
**Changes:** - Use in-proc methods for getting OS version number (#1240, #1264) - Update System.CommandLine (#1265) - Suppress GUI from command-line argument (#1267) - Add github (login|logout|list) commands (#1267) - cURL Cookie file support (#1251) - Update target framework on Mac/Linux to .NET 7 (#1274, #1282) - Replace JSON.NET with System.Text.Json (#1274) - Preserve exact redirect URI formatting in OAuth requests (#1281) - Use IP localhost redirect for GitHub (#1286) - Use WWW-Authenticate headers from Git for Azure Repos authority (#1288) - Better GitHub Enterprise Managed User (EMU) account support (#1190)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We are spending about 45ms on macOS to read version information by shelling out to
sw_vers
on each run of GCM.Let's try and be smarter and use BCL APIs, system APIs or file-based sources for the OS and distribution information before resorting to external processes.
In my testing, on macOS, we went from 45ms to 4.5ms (10x speedup).
Note that we are now also getting something a little bit more useful for Linux:
Before:
After: