Giter Site home page Giter Site logo

forki / linq.expression.optimizer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thorium/linq.expression.optimizer

0.0 3.0 0.0 286 KB

System.Linq.Expression expressions optimizer. http://thorium.github.io/Linq.Expression.Optimizer

License: The Unlicense

Batchfile 0.35% F# 96.51% Shell 3.15%

linq.expression.optimizer's Introduction

Issue Stats Issue Stats

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)

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!

linq.expression.optimizer's People

Contributors

thorium avatar stefh avatar

Watchers

Steffen Forkmann avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.