
RoslynLinqRewrite – Compiles C# by rewriting and optimising LINQ expressions - Halienja
https://github.com/antiufo/roslyn-linq-rewrite
======
mwsherman
Looks nice. A lot of people don’t realize how expensive Linq can be. That
said, my preference for most (source) codegen is in the editor – this would be
nice as an editor plugin.

~~~
olmo
It's true, but 95% of the cases you get much better results by using the right
data structures (dictionaries) instead of transforming queries to loops. Still
is a very cool thing, hopefully is standardized into Roslyn

~~~
platz
How would the provided example be better realized as a dictionary?

~~~
SideburnsOfDoom
All true, but the example is a demo that doesn't do anything useful, and not
typical code.

------
damieng
Worth bearing in mind that this only helps if you are using LINQ against in-
memory objects (i.e. LINQ to Objects). Depending on how this detects
IQueryable providers it will either skip it, break it or worse of all silently
'work' but pull all the remote data into memory for evaluation. I'm hoping
it's skip.

~~~
matthewwarren
This project only works with IEnumerable, not IQueryable, see
[https://github.com/antiufo/roslyn-linq-
rewrite/blob/09216a3b...](https://github.com/antiufo/roslyn-linq-
rewrite/blob/09216a3b2ab53474a93db861435c056523f194d0/RoslynLinqRewrite/RoslynLinqRewrite/LinqRewriter.Rules.cs#L167-L181)
for instance.

I guess this is for exactly the reasons you talk about, i.e. once it's working
with Expression tress too much is unknown and any optimisations would be v.
risky.

------
duaneb
Looks cool!

> No support for F#

Why is this? Is it a macro (as opposed to working with bytecode directly)?

~~~
wluu
Because Roslyn[1] itself can only understand C# and VB.NET.

[1] `The .NET Compiler Platform ("Roslyn") provides open-source C# and Visual
Basic compilers with rich code analysis APIs.` -
[https://github.com/dotnet/roslyn](https://github.com/dotnet/roslyn)

------
yread
It would be more interesting to apply it selectively to LINQ on hot code paths
and keep LINQ's readability where performance and allocations are not a
concern

~~~
SideburnsOfDoom
If this happens as a step during each compilation then you probably do keep
readability of the input source code.

~~~
yread
Sure, but when you start debugging you will see something else happening than
what is in the input source code.

------
CurtHagenlocher
If only C# had LISP-style macros... .

