Skip to content

Optimize LINQ batch item processing for queries with overridden result type #2350

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

Merged
merged 5 commits into from
May 13, 2020

Conversation

bahusoid
Copy link
Member

No description provided.

public static class LinqBatchItem
{
internal static ConcurrentDictionary<System.Type, Func<ILinqBatchItem, IList>> GetResultsForTypeDic = new ConcurrentDictionary<System.Type, Func<ILinqBatchItem, IList>>();
Copy link
Member Author

@bahusoid bahusoid Apr 16, 2020

Choose a reason for hiding this comment

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

Let's generate compiled delegate returning typed results and cache it per result type.
Example of generated delegate for int? type:

IList GetTypedResuls(ILinqBatchItem batchItem) => batchItem.GetTypedResults<int?>();

It's OK to have static cache as it will contain only few items (and for now it's only for nullable types)

return null;
}
var elementType = _postExecuteTransformer.Method.GetParameters()[1].ParameterType.GetGenericArguments()[0];
if (typeof(T).IsAssignableFrom(elementType))
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need to do such analysis - if type is overridden its type provided in ExpressionToHqlTranslationResults.ExecuteResultTypeOverride

@hazzik
Copy link
Member

hazzik commented Apr 16, 2020

What is the performance improvement?

@bahusoid
Copy link
Member Author

What is the performance improvement?

Negligible to investigate. That's some old work that's been dusting in my local repos. If you think that compiled expression generation looks ugly or may worsen the perf - I will undo this part and just leave it as clean up PR that removes unnecessary GetResultTypeIfChanged

@hazzik

This comment has been minimized.

@bahusoid

This comment has been minimized.

@bahusoid

This comment has been minimized.

@hazzik

This comment has been minimized.

@fredericDelaporte fredericDelaporte added this to the 5.3 milestone May 9, 2020
@hazzik hazzik merged commit ae0f1f7 into nhibernate:master May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants