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

perf: Cleanup allocations + missing ConfigureAwait's #124

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

austindrenski
Copy link
Member

Minor stuff, but noticed these while reviewing/evaluating the source for an upcoming project and figured they're most likely oversights, so opening a quick PR to help out.

@austindrenski austindrenski requested a review from a team as a code owner January 5, 2024 23:30
@github-actions github-actions bot requested review from bacherfl and toddbaert January 5, 2024 23:31
@austindrenski austindrenski force-pushed the flagd-tlc branch 2 times, most recently from a25cca3 to 57e3066 Compare January 6, 2024 00:35
@austindrenski austindrenski changed the title Cleanup allocations + missing ConfigureAwait's perf: Cleanup allocations + missing ConfigureAwait's Jan 6, 2024
@austindrenski
Copy link
Member Author

Had inadvertently dropped a break in the original version, but have since fixed that and cleaned up the sign-off and commit title. Should be ready for review and CI checks now.

@@ -519,7 +521,7 @@ private static Value ConvertToPrimitiveValue(ProtoValue value)

private Service.ServiceClient BuildClientForPlatform(Uri url)
{
var useUnixSocket = url.ToString().StartsWith("unix://");
var useUnixSocket = url.Scheme is "unix";
Copy link
Member

Choose a reason for hiding this comment

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

Above, you use string.Equals(url.Scheme, "unix", StringComparison.OrdinalIgnoreCase). Is there a reason to do it differently here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily. I'm starting to see the is {const string} pattern more often in the wild for exact/ordinal matching, so since StartsWith(string) implies StartsWith(string, StringComparison.Ordinal), I converted it to a constant ordinal pattern out of habit.

But I can certainly convert it to string.Equals(url.Scheme, "unix", StringComparison.Ordinal) for consistency if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

I have a weak preference for the consistency in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough! Updated:

diff --git a/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs b/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
index 6496ebc..cdb5f26 100644
--- a/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
+++ b/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
@@ -516,7 +516,7 @@ namespace OpenFeature.Contrib.Providers.Flagd

         private Service.ServiceClient BuildClientForPlatform(Uri url)
         {
-            var useUnixSocket = url.Scheme is "unix";
+            var useUnixSocket = string.Equals(url.Scheme, "unix", StringComparison.Ordinal);

             if (!useUnixSocket)
             {

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

Approving with a question. Thanks again!

Additionally, do you think it's worth adding something like this as we have in the SDK?

@austindrenski
Copy link
Member Author

Approving with a question. Thanks again!

Additionally, do you think it's worth adding something like this as we have in the SDK?

I'm definitely in the enable all analyzers camp, so very much in favor of setting dotnet_diagnostic.CA2007.severity = error in this repo, but didn't want to overstep on this PR.

@austindrenski
Copy link
Member Author

austindrenski commented Jan 8, 2024

Confused on the test re-failures, given they passed locally last week. I'll re-re-run them locally and see what's going on...

@toddbaert
Copy link
Member

toddbaert commented Jan 8, 2024

Confused on the test re-failures, given they passed locally last week. I'll re-re-run them locally and see what's going on...

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
	EventStream(any Empty, <null>, <null>, System.Threading.CancellationToken)
Actually received 1211 matching calls:
	EventStream({ }, <null>, <null>, System.Threading.CancellationToken)

@austindrenski I guess this is a side-effect of adding ConfigureAwait?

@austindrenski
Copy link
Member Author

Confused on the test re-failures, given they passed locally last week. I'll re-re-run them locally and see what's going on...

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
	EventStream(any Empty, <null>, <null>, System.Threading.CancellationToken)
Actually received 1211 matching calls:
	EventStream({ }, <null>, <null>, System.Threading.CancellationToken)

@austindrenski I guess this is a side-effect of adding ConfigureAwait?

Locally it seemed to be from that erroneously dropped break from the switch => if/else sequence, so re-re-testing/-reviewing that change now...

@austindrenski
Copy link
Member Author

austindrenski commented Jan 8, 2024

Confused on the test re-failures, given they passed locally last week. I'll re-re-run them locally and see what's going on...

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
	EventStream(any Empty, <null>, <null>, System.Threading.CancellationToken)
Actually received 1211 matching calls:
	EventStream({ }, <null>, <null>, System.Threading.CancellationToken)

@austindrenski I guess this is a side-effect of adding ConfigureAwait?

Locally it seemed to be from that erroneously dropped break from the switch => if/else sequence, so re-re-testing/-reviewing that change now...

doh! mis-converted the original switch by retaining the break statements in the first place.

updated the pr, but interesting bit is here:

diff --git a/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs b/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
index 65e5c03..481a724 100644
--- a/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
+++ b/src/OpenFeature.Contrib.Providers.Flagd/FlagdProvider.cs
@@ -325,18 +325,10 @@ namespace OpenFeature.Contrib.Providers.Flagd
                         var response = call.ResponseStream.Current;

                         if (string.Equals(response.Type, "configuration_change", StringComparison.OrdinalIgnoreCase))
                         {
                             HandleConfigurationChangeEvent(response.Data);
-                            break;
                         }
-
-                        if (string.Equals(response.Type, "provider_ready", StringComparison.OrdinalIgnoreCase))
+                        else if (string.Equals(response.Type, "provider_ready", StringComparison.OrdinalIgnoreCase))
                         {
                             HandleProviderReadyEvent();
-                            break;
                         }
-
-                        break;
                     }
                 }
                 catch (RpcException ex) when (ex.StatusCode == StatusCode.Unavailable)

Minor stuff, but noticed these while reviewing/evaluating the source
for an upcoming project and figured they're most likely oversights,
so opening a quick PR to help out.

Signed-off-by: Austin Drenski <[email protected]>
@toddbaert
Copy link
Member

toddbaert commented Jan 8, 2024

doh! mis-converted the original switch by retaining the break statements in the first place.

I noticed this about the same time you force pushed the fix. Understandable mistake 😅

@toddbaert toddbaert merged commit e3d0f06 into open-feature:main Jan 8, 2024
10 checks passed
@austindrenski austindrenski deleted the flagd-tlc branch January 8, 2024 16:37
ericpattison pushed a commit to ericpattison/dotnet-sdk-contrib that referenced this pull request Jan 9, 2024
ericpattison pushed a commit to ericpattison/dotnet-sdk-contrib that referenced this pull request Jan 10, 2024
ericpattison pushed a commit to ericpattison/dotnet-sdk-contrib that referenced this pull request Jan 10, 2024
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