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
Make the static constructor of PSVersionInfo run faster for stable PowerShell releases
#18210
base: master
Are you sure you want to change the base?
Conversation
| rawGitCommitId = mainVersion; | ||
| } | ||
| string rawGitCommitId = ProductVersion.AsSpan(index).StartsWith(" Commits: ") | ||
| ? "v" + ProductVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g") |
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.
No optimization for private builds, intentionally.
|
|
||
| s_psSemVersion = new SemanticVersion(mainVersion); |
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.
Avoid calling SemanticVersion(string), which needs to parse the argument.
The PS version format is pre-defined, so we can greatly simplify the parsing.
| titlePattern = Regex.Escape(titlePattern) | ||
| .Replace(@"\{1}", ".*") | ||
| .Replace(@"\{0}", Regex.Escape(prefix)); | ||
| if (!Regex.IsMatch(this.WindowTitle, titlePattern)) |
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.
This is to get rid of using Regex at startup, which is not necessary.
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |


PR Summary
Make the static constructor of
PSVersionInforun faster for stable PowerShell releases.Major changes are:
SemanticVersion.Parse(string).SemanticVersionobject.SementicVersionobject.$PSVersionTable.GitCommitIdto actually use the release tagv7.x.x. Thevwas missing previously.Versioninstead ofSemanticVersion, to avoid the overhead of casting when using them for$PSVersionTable.PSCompatibleVersions.ConsoleHostRawUserInterfaceto not useRegex.PR Context
The change reduces the time to run
PSVersionInfotype initializer from about25msto11mson my dev machine.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.