Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations. For side-effect free Expressions. No compilation-subjective optimizations. This is meant to be used with expressions that are not compiled but transferred to other domain.
Example as a quote. There are various other cases also.
- Replace constants comparisons:
3 < 4 -> true
- Remove anonymous types:
new AnonymousObject(Item1 = x, Item2 = "").Item1 -> x
- Cut not used condition:
if false then x else y -> y
- Remove not:
not(false) -> true
- Binary tree balancing:
a or (b or (c or (d or (e or (f or (g or h)))))) -> ((a or b) or (c or d)) or ((e or f) or (g or h))
- Captured closure constant ("free variable") evaluation:
y = 3 and (y + x) -> (3 + x)
- Execute simple math:
5 * 3 -> 15
Boolean algebra reductions:
(x or y) and (x or z) -> x or (y and z)
false or y -> y
true or x -> true
x and (x or y) -> x
y or y -> y
x and not(x) -> false
not(not(y)) -> y
not(x) and not(y) -> not(x or y)
PM> Install-Package Linq.Expression.Optimizer
Currently Linq.Expression.Optimizer is using .NET Framework 4.5.
This example demonstrates using a function defined in this sample library.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
For more motivation why to use this, see: Tutorial
The library comes with comprehensible documentation.
It can include tutorials automatically generated from
*.fsx files in docs/content/.
The API reference is automatically generated from Markdown comments in the library implementation.
Tutorial contains a further explanation of this sample library.
API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.
This component is in use in a large scale enterprise application for simplifying and streamlining key financial processes. There is a huge data processing-pipeline with thousands of different SQL-clauses (some also very complex) against separate Oracle server cluster. The pipeline used pure EntityFramework and was converted to use LinqKit with Linq.Expression.Optimizer. The process was performance tested multiple times, and the execution time was dropped from 15h 30min to 14h 30min, mainly due to delivering less CPU usage to Oracle servers.
The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.
The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.