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

Use compiled expression in AliasToBeanResultTransformer #2021

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented Feb 25, 2019

Possible breaking change:
As now expression is compiled on first transformation - this transformer can't be reused for different queries. Transfomer can still be reused but only for the same query.

Perf comparison for 5 aliases and 50 000 transformations on my machine (see #2015 with side by side comparison):
300 ms vs 15 ms for Compiled version

@hazzik
Copy link
Member

hazzik commented Feb 26, 2019

We can cache the compiled delegate by aliases to avoid breaking changes.

@bahusoid
Copy link
Member Author

Yeah. But is it worth it? Current transformer design means that lookup is required on each record transformation.
I don't think that this reusing is commonly used (as our docs say nothing about it) and from my tests didn't saves much. If you are in to such optimizations - you better cache transformer per query for yourself.

@@ -310,6 +334,8 @@ public bool Equals(AliasToBeanResultTransformer other)
{
return true;
}
if (GetType() != other.GetType())
return false;
return Equals(other._resultClass, _resultClass);
Copy link
Member

Choose a reason for hiding this comment

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

Equality is somewhat troublesome with this PR changes. Can we really consider equal two AliasToBeanResultTransformer having been used for different queries? They will not be usable on the same queries, and so are not equivalent.
I think equality here needs to be changed for reference equality only. Or @hazzik suggestion, caching _transformer to be used by aliases, needs to be done.

Copy link
Member

Choose a reason for hiding this comment

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

I think equality here needs to be changed for reference equality only.

This would not be enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I feel like it's either better to provide a separate class for compiled version or just close this PR and leave it be reflection based. As I don't like this alias caching idea - it unnecessary complicates things (eg. should this caching be thread safe? Looks like it should to support possible static instance of transformer)

src/NHibernate/Transform/AliasToBeanResultTransformer.cs Outdated Show resolved Hide resolved
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.

None yet

3 participants