GithubHelp home page GithubHelp logo

i-e-b / linqoptimizer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nessos/linqoptimizer

0.0 2.0 0.0 2.17 MB

An automatic query optimizer-compiler for Sequential and Parallel LINQ.

Home Page: http://nessos.github.io/LinqOptimizer/

License: Other

C# 30.45% F# 69.26% Shell 0.29%

linqoptimizer's Introduction

LinqOptimizer

An automatic query optimizer-compiler for Sequential and Parallel LINQ.

Build Status

Head (branch master), Build & Unit tests

  • Windows/.NET Build status
  • Mac OS X/Mono 3.2.x Build Status

Introduction

LinqOptimizer compiles declarative LINQ queries into fast loop-based imperative code. The compiled code has fewer virtual calls and heap allocations, better data locality and speedups of up to 15x (Check the [Performance] (https://github.com/nessos/LinqOptimizer/wiki/Performance) page).

The main idea is that we lift query sources into the world of Expression trees and after various transformations-optimizations we compile them into IL for efficient execution.

var query = (from num in nums.AsQueryExpr() // lift
             where num % 2 == 0
             select num * num).Sum();
             
Console.WriteLine("Result: {0}", query.Run()); // compile and execute

For F# we support functional pipelines and support for F# style LINQ queries is in development.

let query = nums
            |> Query.ofSeq
            |> Query.filter (fun num -> num % 2 = 0)
            |> Query.map (fun num -> num * num)
            |> Query.sum
             
printfn "Result: %d" <| Query.run query // compile and execute

Install via NuGet

Install-Package LinqOptimizer.CSharp
Install-Package LinqOptimizer.FSharp

Optimizations

  • Lambda inlining
  • Loop fusion
  • Nested loop generation
  • Anonymous Types-Tuples elimination
  • Specialized strategies and algorithms

The expression

var query = (from num in nums.AsQueryExpr()
             where num % 2 == 0
             select num * num).Sum();

will compile to

int sum = 0;
for (int index = 0; index < nums.Length; index++)
{
   int num = nums[index];
   if (num % 2 == 0)
      sum += num * num;
}

and for the parallel case

var query = (from num in nums.AsParallelQueryExpr()
             where num % 2 == 0
             select num * num).Sum();

will compile to a reduce-combine style straregy

Parallel.ReduceCombine(nums, 0, 
                          (acc, num) => { 
                                       if (num % 2 == 0)  
                                         return acc + num * num; 
                                       else
                                         return acc; 
                          }, (left, right) => left + right);

Future work

  • Many missing operators
  • New specialized operators
  • Even more optimizations

References

LinqOptimizer draws heavy inspiration from

linqoptimizer's People

Contributors

palladin avatar eiriktsarpalis avatar biboudis avatar i-e-b avatar

Watchers

 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.