-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Address some low-hanging fruit to use newer/better .NET features #11448
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
Conversation
This is based only on code inspection / static analysis / searching around. It is not based on profiling.
cc: @MihaZupan, fyi on the SearchValues usage |
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.
PR Overview
This pull request updates several components and unit tests to leverage newer and more efficient .NET features, simplifying asynchronous operations and collection enumeration while improving code readability. Key changes include:
- Replacing manual string concatenation with string.Create under NET.
- Using WaitAsync and AsTask for asynchronous operations in place of older patterns.
- Switching from manual enumerator conversions (GetEnumerator().ToArray()) to direct ToArray() calls.
- Refactoring thread naming and static field declarations to use string interpolation and readonly modifiers.
- Updating unit tests to iterate over character ranges with a for loop and checking invalid characters using explicit conditions.
Changes
File | Description |
---|---|
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs | Improved string creation and wait logic based on target .NET version. |
src/Build.UnitTests/Globbing/MSBuildGlob_Tests.cs | Updated iteration over invalid path characters and using explicit arrays for file name chars. |
src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs | Switched from IndexOf to Contains for clarity. |
src/Build/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs | Changed thread identifier usage to Environment.CurrentManagedThreadId. |
src/Build.UnitTests/BackEnd/CacheAggregator_Tests.cs | Simplified collection enumerations using ToArray(). |
src/Build/BackEnd/Client/MSBuildClientPacketPump.cs | Updated asynchronous read operations to use AsTask. |
src/Build.UnitTests/FileUtilitiesRegex_Tests.cs | Removed redundant regex match check. |
src/Build/BackEnd/Components/FileAccesses/FileAccessManager.cs | Updated string interpolation for file access prefix. |
src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs | Removed unnecessary ContinueWith calls during asynchronous plugin initialization. |
src/Build/BackEnd/BuildManager/BuildRequestEngine/BuildRequestEngine.cs | Adjusted logging to use new thread id retrieval. |
src/Build.UnitTests/BackEnd/ConfigCache_Tests.cs, CacheAggregator.cs, IsolateProjects_Tests.cs, ResultsCache_Tests.cs, ResultCacheBasedBuilds_Tests.cs | Consolidated and simplified collection enumeration calls using ToArray(). |
src/Build/BackEnd/Components/Communications/NodeProviderInProc.cs, NodeEndpointInProc.cs, TranslatorExtensions.cs, LoggingService.cs | Refactored thread naming, static fields, and lazy initialization to newer .NET constructs. |
Copilot reviewed 191 out of 191 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/Build.UnitTests/Globbing/MSBuildGlob_Tests.cs:74
- Verify that iterating from 0 to 127 covers all invalid path characters as provided by FileUtilities.InvalidPathChars; if the set includes characters outside this range, adjust the loop boundaries accordingly.
for (int i = 0; i < 128; i++)
src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs:118
- Ensure that exceptions thrown during asynchronous plugin initialization remain intentionally unobserved; if not, consider adding proper error handling to capture and log any initialization failures.
_ = GetProjectCachePluginAsync(projectCacheDescriptor, projectGraph, buildRequestConfiguration: null, requestedTargets, cancellationToken);
Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more
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.
(am halfway done)
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.
137 / 191
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.
30/191, review in progress.
100/191 so far, no issues. |
This reverts commit aa508b8. No need to worry about speed on this path so let's just match existing behavior.
Perfstar results look promising - the PR has a visible positive impact on Evaluation. |
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.
We want this one. I'll look if there is an easy way to resolve the conflicts and there is one comment from Rainer for the named pipes - do we want to revert that one so that we can merge the pipe change from @ccastanedaucf without issues, then revisit if necessary?
Co-authored-by: Rainer Sigwald <[email protected]>
Co-authored-by: Rainer Sigwald <[email protected]>
Thanks for getting it over the finish line, @SimaTian. |
This is based only on code inspection / static analysis / searching around. It is not based on profiling. I do not know how much of an impact any of these have; we could choose to cherry-pick from this if there are particular areas that demonstrate gains.