Apply some obvious rich debug info optimizations #73373
Merged
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.
When rich debug info is enabled we send MethodDetails events for all inlinees as otherwise no information for those may have been sent (in case they have not been jitted). During rundown this was sending a lot of duplicate events, so use a hash set to avoid this. On Avalonia.ILSpy which has around ~33k methods jitted, we go from ~94k MethodDetails events to ~43k MethodDetails events on rundown.
In addition, compress rich debug info when stored in the runtime. For the above scenario the memory overhead of rich debug info goes from 7 MB -> 2.1 MB.
Also optimize the format we use for the ETW events. While we do not use the same delta compression as the runtime storage, we now avoid sending out padding and also use a smaller type for the offset mappings source type. The average size of a rich debug info ETW event goes from 259 bytes to 219 bytes for the above scenario.
The net result is the following for two rundowns of Avalonia.ILSpy (I clicked around a bit and did a few actions before enabling the rundown. EventID(189) is the rich debug info event)
Before:
After:
There should not be any effect of this PR except when rich debug info is enabled.
I would like to get this in .NET 7. There is more work to be done here for .NET 8, e.g. by avoiding storing method handles when we can get it based on IL offset, but this fixes the most glaring issues.