Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Do not check if key is present before removing item in AuthenticationProperties #1064

Merged
merged 1 commit into from
Nov 14, 2018

Conversation

drieseng
Copy link
Contributor

Eliminating the extra lookup yields the following result:

Before:

Method Mean Error StdDev Op/s Gen 0 Allocated
NullValue_KeyPresent 123.84 ns 2.1405 ns 1.8975 ns 8,074,763.9 0.0036 328 B
NullValue_KeyNotPresent 41.63 ns 0.5963 ns 0.5577 ns 24,022,181.2 0.0021 192 B

After:

Method Mean Error StdDev Op/s Gen 0 Allocated
NullValue_KeyPresent 107.04 ns 0.9192 ns 0.8598 ns 9,342,589.5 0.0038 328 B
NullValue_KeyNotPresent 39.53 ns 0.5507 ns 0.4882 ns 25,300,109.1 0.0021 192 B

Benchmark is available here.

Use Nullable<T>.GetValueOrDefault() instead of Nullable<T>.Value when it is known to have a value.
Copy link
Contributor

@poke poke left a comment

Choose a reason for hiding this comment

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

Good idea to test the protected utility methods with a subclass. I hadn’t thought of that!

@drieseng
Copy link
Contributor Author

@poke That's knowledge you gain for free by aging :-)

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

I do wonder what motivated this change. I would not expect removing items from AuthProperties to be that common.

@Tratcher Tratcher self-assigned this Nov 14, 2018
@Tratcher Tratcher added this to the 3.0.0 milestone Nov 14, 2018
@drieseng
Copy link
Contributor Author

@Tratcher I just happened to stumble upon it. I didn't come up in profiling session or anything.

@poke
Copy link
Contributor

poke commented Nov 14, 2018

@Tratcher I would assume that this was motivated by the Value to ValueOrDefault() change and then the key checks were seen in the code.. 😄

@Tratcher
Copy link
Member

Note we don't generally accept changes that are unlikely to have a demonstrable production impact. In this case there's the added benefit that it makes the code simpler.

@Tratcher Tratcher merged commit ea1ee2b into aspnet:master Nov 14, 2018
jkotalik pushed a commit that referenced this pull request Nov 17, 2018
Use Nullable<T>.GetValueOrDefault() instead of Nullable<T>.Value when it is known to have a value.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants