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
Optimize filter expressions #7005
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7005 +/- ##
=======================================
Coverage 69.84% 69.85%
=======================================
Files 2602 2602
Lines 130049 130056 +7
=======================================
+ Hits 90836 90846 +10
+ Misses 39213 39210 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…ons by using parameter overload
BenchmarksAll benchmarks are performed by invoking the associated method in the FilterExpressionBuilder (such as Equals) using static parameters in order to measure the filter expressions in isolation Commit be56f19Applies to all filter operators except for list operators All / Any / Some / None Avoids reflection by using cached delegates for creating the parameter expression for the value
Commit 51ae3feApplies to in and nin operators Avoids reflection by using cached delegates for creating the parameter expression for the value
Commit 5631694Applies to list operators All / Any / Some / None Simply removes an array allocation by using a Expression overload which accepts the parameters directly
Omitted benchmarks for None / Some since they are just All / Any wrapped with a Commit 01642d2Applies to all operators when the filter value is null Eliminates lambda expression allocation by caching the expression used to represent null for the given type
Other operators omitted for brevity Commit 6d0b9e8Applies to all operators when the filter value is true or false Eliminates lambda expression allocation by using a static constant for true and false
Other operators omitted for brevity |
Added two additional commits that cache the default expression for representing a null value for a given type as well as constant expressions for representing boolean true and false. This avoids a lambda expression allocation for these values when used in a filter |
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.
Thanks @nikolai-mb for the pull request, very clean PR.
Just changed a few formatting things
@michaelstaib LGTM, if tests are green, lets go
will go in today |
Hey @nikolai-mb, I send this trough our tests and it breaks 78 tests ... Have you run the data tests? |
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.
Tests Fail
It looks like the parameters get removed
|
while this statement would still work other tests just completely break with no usable SQL anymore. Also we must ensure that even in this case we have a parametrized SQL statement. |
In order to run the tests you need to have docker running on your system. |
No, i assumed the same tests would run as part of the PR pipeline. I've tested the code against a real API running sql server and EF Core and so i was confident in the code submitted. I'll have a look at the data-tests specifically when i have a minute, sorry for the inconvenience |
Pushed two fixes, the first one fixes the lack of parameterization from #7005 (comment) Second one fixes a Nullable<bool> == bool comparison which resulted in expressions that were invalid. Resolved this by introducing two additional expressions for nullable true and false. There's some noise in my tests and several snapshot tests are failing caused only by CRLF / LF diff, not sure if that's the case for you. I currently have 12 failing tests, which is the same as i have in the main branch so i think everything related to this PR passes. Apologies for overlooking this, could you do another sanity check and run the tests on your end with the latest changes? |
its the same tests. But somehow the build agent looks green. |
@nikolai-mb thank you for your contribution! |
Adds delegate caching for filter expressions using concurrent dictionaries for improved performance and reduced allocations.
Second commit is only related to in / nin filters and eliminates a 5.5 KB allocation that occurs every time the expression is applied by caching MethodInfo for invoking Expression.Call
Closes #6996