-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Remove redundant guid parsing #120413
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
Remove redundant guid parsing #120413
Conversation
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.
Pull Request Overview
This PR optimizes GUID creation by replacing string-based parsing with direct constructor calls using hexadecimal values. This change eliminates the runtime overhead of parsing GUID strings while maintaining the same GUID values.
Key changes:
- Replace
new Guid(string)
calls withnew Guid(uint, ushort, ushort, byte, byte, byte, byte, byte, byte, byte, byte)
constructor - Add inline comments showing the original GUID string values for reference
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
RuntimeEventSource.cs | Converts EventSourceGuid initialization from string parsing to direct constructor with hex values |
EventSource.cs | Converts Metrics EventSource GUID initialization from string parsing to direct constructor with hex values |
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
Backport candidate? (along with #120364) |
I believe so |
It seems other related fixes (i.e. #120422) are also in progress. We can batch them in a backport PR. |
/backport to release/10.0 |
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18284663931 |
There is now an analyser: MA0176: Optimize guid creation |
I don't think it should be an analyzer. we can optimize this in JIT. |
In Tier0 where the Guids are often used for one-time registrations? I think it is fine for this to be an analyzer. |
Well, T0 can be fixed by prejitting 🤷 or with a simple jit intrinsic that will be T0 friendly. My concern that it doesn't look nice. Difficult to search, copy and replace with a different Guid. |
I wonder if we could do something at compile time using source generators: [GeneratedGuid("20752bc4-c151-50f5-f27b-df92d8af5a61")]
internal static partial Guid EventSourceGuid; |
Something like main...am11:runtime:feature/jit/guid-intrinsic? (credit to copilot 🤖) |
There is nothing nice about users having to inline magic GUIDs into their code in any shape or form. GUIDs should be auto generated and out of sight, and whatever is autogenerating them can make sure to use the efficient constructor. I do not think it is worth burning our complexity budget on things like this. It would be a different story if GUID parsing got optimized without being special cased in any way, and it was just used as an example of powerful optimizations in the perf blog post. I would be fine with that. |
Context: #120288 (comment)