Skip to content

Conversation

@SergeiPavlov
Copy link
Collaborator

Memoize result of heavy reflection computation

@SergeiPavlov SergeiPavlov requested review from botinko and removed request for botinko January 6, 2026 22:46
@SergeiPavlov SergeiPavlov changed the base branch from master to master-servicetitan January 6, 2026 22:46
@SergeiPavlov SergeiPavlov requested a review from botinko January 6, 2026 22:46
@SergeiPavlov SergeiPavlov changed the title Visit member Optimize Translator.VisitMember() Jan 6, 2026
private static readonly Type OrmQueryableExtensionsType = typeof(QueryableExtensions);
private static readonly IReadOnlyList<ParameterExpression> ParameterContextParams = [Expression.Parameter(WellKnownOrmTypes.ParameterContext, "context")];
private static readonly ParameterExpression ParameterContextParam = Expression.Parameter(WellKnownOrmTypes.ParameterContext, "context");
private static readonly ConcurrentDictionary<(Type Type, MemberInfo MemberInfo), PropertyInfo> memberCache = new();
Copy link

Choose a reason for hiding this comment

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

It looks like it could be kinda big in ST context. Could you measure actual cost of sourceExpression.Type.GetProperty(memberInfo.Name, memberInfo.GetBindingFlags())? Reflection has caches, maybe it's cheap.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be big, but all Type, MemberInfo, PropertyInfo are reused
so we allocate this memory anyway. Just don't want to spend time on reflection logic

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.

2 participants