-
Notifications
You must be signed in to change notification settings - Fork 160
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 Fix CreateEtags #1128
Perf Fix CreateEtags #1128
Conversation
f9641d8
to
a710d78
Compare
src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs
Show resolved
Hide resolved
foreach (IEdmStructuralProperty etagProperty in concurrencyProperties) | ||
{ | ||
properties ??= new Dictionary<string, object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a certain type of way about checking whether the properties
dictionary is null in each iteration? More CPU cycles and feels like we're sacrificing one thing for the other. If we must go this route, then the following would also be candidate:
IEnumerator<IEdmStructuralProperty> concurrencyPropertiesEnumerator = concurrencyProperties.GetEnumerator());
if (concurrencyPropertiesEnumerator.MoveNext())
{
properties = new Dictionary<string, object>();
do
{
IEdmStructuralProperty etagProperty = concurrencyPropertiesEnumerator.Current;
properties.Add(etagProperty.Name, resourceContext.GetPropertyValue(etagProperty.Name));
}
while (concurrencyPropertiesEnumerator.MoveNext());
}
At least this way we're not checking if properties
dictionary is null in each iteration.
Whether the code is clean and easy-to-follow is a different matter altogether...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases we do not have concurrency properties..
10c21cd
to
a73bd98
Compare
foreach (IEdmStructuralProperty etagProperty in concurrencyProperties) | ||
{ | ||
properties ??= new SortedDictionary<string, object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I think gathogo
's suggestion of using MoveNext()
instead of doing a null-check on each iteration wasn't that bad. But since this code path isn't that common, not sure it makes material difference.
This PR fixes some of the issues raised in this PR: #1111:
I've made the following updates to the
CreateEtag
method:These changes have the following CPU Usage improvements:
Before changes:
After changes: