Linq.Expression.Optimizer
1.0.13
See the version list below for details.
dotnet add package Linq.Expression.Optimizer --version 1.0.13
NuGet\Install-Package Linq.Expression.Optimizer -Version 1.0.13
<PackageReference Include="Linq.Expression.Optimizer" Version="1.0.13" />
paket add Linq.Expression.Optimizer --version 1.0.13
#r "nuget: Linq.Expression.Optimizer, 1.0.13"
// Install Linq.Expression.Optimizer as a Cake Addin
#addin nuget:?package=Linq.Expression.Optimizer&version=1.0.13
// Install Linq.Expression.Optimizer as a Cake Tool
#tool nuget:?package=Linq.Expression.Optimizer&version=1.0.13
Linq.Expression.Optimizer
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.
Supported frameworks: Net 3.5, Net 4.5-... (and Mono), .NET Standard 1.6 (so also .NET Core)
Supported optimizations
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:
- gather
(x or y) and (x or z) -> x or (y and z)
- identity
false or y -> y
- annihilate
true or x -> true
- absorb
x and (x or y) -> x
- idempotence
y or y -> y
- complement
x and not(x) -> false
- doubleNegation
not(not(y)) -> y
- deMorgan
not(x) and not(y) -> not(x or y)
- gather
Background
This is a side-track from SQLProvider, excelent tool that is kind of OR-mapper with auto-generated objects, so it compiles any databases to .NET-language, and works fast on design time in Visual Studio or other editors.
But I needed better SQL-queries. So this optimses .NET LINQ-expressions. These expressions were not ment to be compiled so Nessos LinqOptimizer was not the right tool. I thought that .NET would optimize these automatically, but no.
Read the Getting started tutorial to learn more.
Documentation: http://thorium.github.io/Linq.Expression.Optimizer
Maintainer(s)
If you want more optimizations, please feel free to send PRs!
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard1.6 netstandard2.0 netstandard2.1 |
.NET Framework | net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen30 tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
- FSharp.Core (>= 4.1.18)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Linq.Expression.Optimizer:
Package | Downloads |
---|---|
XSpecification.Linq
XSpecification is an implementation of Specification pattern for Linq and Elasticsearch |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Linq.Expression.Optimizer:
Repository | Stars |
---|---|
scottksmith95/LINQKit
LINQKit is a free set of extensions for LINQ to SQL and Entity Framework power users.
|
Version | Downloads | Last updated |
---|---|---|
1.0.15 | 118 | 3/7/2023 |
1.0.13 | 148,421 | 5/27/2019 |
1.0.12 | 31,857 | 8/31/2018 |
1.0.11 | 26,420 | 1/1/2018 |
1.0.10 | 866 | 1/1/2018 |
1.0.9 | 23,290 | 6/5/2017 |
1.0.8 | 1,025 | 5/10/2017 |
1.0.7 | 28,317 | 10/7/2016 |
1.0.6 | 890 | 10/6/2016 |
1.0.5 | 851 | 10/5/2016 |
1.0.4 | 1,026 | 10/3/2016 |
1.0.3 | 1,050 | 8/30/2016 |
1.0.2 | 872 | 8/30/2016 |
1.0.1 | 833 | 8/30/2016 |
1.0.0 | 908 | 8/27/2016 |
Look inside a WhereSelectEnumerableIterator, #9