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

Wrap EventSource calls with IsEnabled #2052

Merged
merged 6 commits into from
Feb 21, 2023

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 21, 2023

Wrap event source calls with IsEnabled to avoid Interlocked.Increment calls inside the methods.

Small perf improvement:

  • Before 956,933
  • After 966,092

The perf improvement will be much bigger with AOT + ARM: dotnet/runtime#73246

GrpcEventSource.Log.CallFailed(_status.StatusCode);
}
}
if (GrpcEventSource.Log.IsEnabled())
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're always going to test enabled here, is it worth pulling this into a local around L297, to avoid multiple checks?

Copy link
Member Author

@JamesNK JamesNK Feb 21, 2023

Choose a reason for hiding this comment

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

IsEnabled implementation directly returns a field: https://github.com/dotnet/runtime/blob/463954dbc728470fb21a097188fc3dae91f6cbe4/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L256-L263

IsEnabled is so cheap (probably inlined) that I don't think it's worth it.

_deadline = DateTime.MaxValue;
}
}
}

GrpcCallLog.GrpcStatusError(Logger, status.StatusCode, status.Detail);
GrpcEventSource.Log.CallFailed(status.StatusCode);
if (GrpcEventSource.Log.IsEnabled())
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto hoist covering 3 in a row here

Copy link
Contributor

@mgravell mgravell left a comment

Choose a reason for hiding this comment

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

minor nits re avoidable repeated call; 👍 in principle, and I'll let you decide whether that change is needed

@@ -23,7 +23,7 @@

namespace Grpc.AspNetCore.Server.Internal;

internal class GrpcEventSource : EventSource
internal sealed class GrpcEventSource : EventSource
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 , although with the static readonly Log I would hope that the JIT devirtualizes anyway

Copy link

@EgorBo EgorBo Feb 21, 2023

Choose a reason for hiding this comment

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

👍 , although with the static readonly Log I would hope that the JIT devirtualizes anyway

Yes, jit does that for static readonly

@JamesNK JamesNK merged commit a456d47 into grpc:master Feb 21, 2023
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.

3 participants