Skip to content
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

Trivial fixes #185

Merged
merged 2 commits into from
May 9, 2017
Merged

Trivial fixes #185

merged 2 commits into from
May 9, 2017

Conversation

northtyphoon
Copy link
Member

  1. Make TraceLoggingEventId to implement IDisposable.
  2. Optimize some codes in TraceLoggingEventId for perf.
  3. Fix typos.

1. Make TraceLoggingEventId to implement IDisposable.
2. Optimize some codes in TraceLoggingEventId for perf.
3. Fix typos.
Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a question concerning the importance of using [MethodImpl].

{
/// <summary>
/// Checks to see if eventRecord has TraceLogging meta data associated with it (EVENT_HEADER_EXT_TYPE_EVENT_SCHEMA_TL)
/// and if so updates EventHeader.Id to be an event ID unique to that provider/opcode/meta-data blob.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Were you encountering situations where this method was not already getting inlined? I would prefer to omit this change in light of requests like #153 unless there is a demonstrated problem with the current approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't try to check if the method is inlined or not in runtime. Since I see @vancem has changed TraceEvent lib to target 4.5 and therefore I made the change.
For 3.5 support, do we consider to create a release branch and only do bug fix as needed?

Copy link
Member

@sharwell sharwell May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@northtyphoon Currently the library does not support .NET 3.5, and there is no concrete plan to do so. My suggestion here is to only include this change if it is needed, e.g. if:

  1. PerfView revealed this method in traces (a clear indication that not only is it not being inlined, but it's heavily used)
  2. You saw this method in disassembled JIT code and observed that it wasn't inlined, and knew separately that it's heavily used so it should be
  3. Some other indicator suggesting that the attribute provides value that a user cares about

For me, the bar here is low. I just don't want to include it if no one will notice that it was included, because it makes things a tiny bit more complicated if we ever decide to go back and address the specific request I linked to.

@@ -10,19 +11,20 @@ namespace Microsoft.Diagnostics.Tracing
/// <summary>
/// TraceLoggingEvnetId is a class that manages assigning event IDs (small 64k numbers)
/// to TraceLogging Style events (which don't have them). Because TraceEvent uses EventIDs
/// so fundamentally this difficiency is very problematic.
/// so fundamentally this deficiency is very problematic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 In the future, it helps to place all formatting-only changes and spelling corrections in their own commit, and preferably in their own independent pull request. The primary advantages this offers are:

  1. It's easier to expedite spelling corrections so they don't get tied up in code review
  2. It makes the code review process less complex for the actual code changes (for example, this pull request would contain a one-line change in one file, and nothing else)

The scope in this pull request is fairly small so I don't see it causing a problem, but it adds up pretty quickly so it's a good thing to keep in mind for the future. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. As you said, the scope of this PR is very small, so I combined the changes. I will follow the guidance in the future.
Can you also add the guidance to https://github.com/Microsoft/perfview/blob/master/CONTRIBUTING.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@northtyphoon It seems to be covered well enough already. I mostly assume that people don't read that, or do a cursory look at best. I don't let it bother me when deviations happen and I'm always willing to help if someone isn't sure how to break things up. 😄

foreach (var key in m_traceLoggingEventMap.Keys)
Marshal.FreeHGlobal((IntPtr)key.Provider);
foreach (var kvp in m_traceLoggingEventMap)
Marshal.FreeHGlobal((IntPtr)kvp.Key.Provider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 For those unaware, this change eliminates an unnecessary allocation during the Dispose call. One of the things I'm enjoying about C# 7 (which we aren't currently using on this project) is the ability to gain the efficiency of this form without losing the clarity of the original code by writing this:

foreach (var (key, _) in m_traceLoggingEventMap)
  Marshal.FreeHGlobal((IntPtr)key.Provider);

This form applies a deconstruction to the KeyValuePair<TKey, TValue> in the declaration of key and an unused placeholder _.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the C# 7 tips.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell Pedantic: You can't deconstruct a KeyValuePair like that. You'll need a custom Deconstruct method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pharring It depends on where things are running. It's already added to coreclr in dotnet/coreclr#8560 (not sure what release version that corresponds to). For Roslyn I added the Deconstruct extension method when I used the feature in dotnet/roslyn#19126.

@sharwell
Copy link
Member

sharwell commented May 9, 2017

@northtyphoon Just making sure you saw my question on the use of [MethodImpl] above. 😄

@vancem vancem merged commit 9351d28 into microsoft:master May 9, 2017
@vancem
Copy link
Contributor

vancem commented May 9, 2017

LGTM

@sharwell sharwell modified the milestone: 1.9.55 May 31, 2017
vancem added a commit to vancem/perfview that referenced this pull request Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants