Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Roslyn
  3. roslyn-linq-rewrite

roslyn-linq-rewrite

MITC#

A Roslyn-based compiler that rewrites LINQ expressions into procedural code to minimize allocations and dynamic dispatch in C#.

GitHubGitHub
714 stars28 forks0 contributors

What is roslyn-linq-rewrite?

roslyn-linq-rewrite is a custom C# compiler that rewrites LINQ expressions into optimized procedural code during the build process. It solves performance issues in LINQ-heavy applications by eliminating unnecessary memory allocations and dynamic dispatch overhead while maintaining the original LINQ syntax.

Target Audience

C# developers working on performance-critical applications who use LINQ extensively and want to reduce memory allocations without rewriting their code manually.

Value Proposition

Developers choose roslyn-linq-rewrite because it provides significant performance improvements to existing LINQ code without requiring syntax changes, offering build-time optimizations that outperform runtime solutions like LinqOptimizer.

Overview

Compiles C# code by first rewriting the syntax trees of LINQ expressions using plain procedural code, minimizing allocations and dynamic dispatch.

Use Cases

Best For

  • Optimizing LINQ-heavy C# applications for reduced memory allocations
  • Improving performance in game development or real-time systems using LINQ
  • Reducing garbage collection pressure in long-running .NET services
  • Maintaining LINQ syntax while achieving procedural code performance
  • Build-time optimization of existing codebases without refactoring
  • Performance-critical applications where enumerator allocations are problematic

Not Ideal For

  • Applications heavily dependent on IQueryable for ORM integrations like Entity Framework
  • Projects using Parallel LINQ (PLINQ) extensively
  • Teams working with F# or requiring full LINQ method coverage

Pros & Cons

Pros

Build-Time Optimization

Rewrites LINQ expressions during compilation, not at runtime, reducing overhead without syntax changes, as shown in the decompiled output example.

Significant Allocation Reduction

Minimizes object allocations by eliminating unnecessary enumerators, delegates, and closures, evidenced by the example where only the input array is allocated.

Procedural Code Efficiency

Transforms LINQ chains into optimized for/foreach loops, achieving near-handwritten performance while maintaining LINQ's declarative syntax.

Selective and Safe Optimization

Leaves non-optimizable call chains and IQueryable intact, preventing breaks, and allows exclusions with the [NoLinqRewrite] attribute for control.

Cons

Limited LINQ Method Support

Only optimizes a subset of LINQ methods; advanced operations like GroupBy or Join are not covered, restricting its usefulness for complex queries.

Complex Integration Setup

Requires manual configuration with MSBuild or project.json modifications, which can be error-prone and cumbersome compared to standard compilers.

Edge Case Handling Issues

The README acknowledges bugs with Min/Max and NaN values, indicating that some edge cases might not be correctly optimized or could introduce subtle bugs.

Frequently Asked Questions

Quick Stats

Stars714
Forks28
Contributors0
Open Issues17
Last commit6 years ago
CreatedSince 2016

Tags

#compiler#performance-optimization#csharp#linq#dotnet#roslyn#code-generation#build-tool#memory-optimization

Built With

R
Roslyn
C
C++

Included in

Roslyn734
Auto-fetched 5 hours ago

Related Projects

Dotnet ScriptDotnet Script

Run C# scripts from the .NET CLI.

Stars3,002
Forks179
Last commit1 month ago
RoslynQuoterRoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree

Stars1,090
Forks123
Last commit1 year ago
FlubuCoreFlubuCore

A cross platform build and deployment automation system for building projects and executing deployment scripts using C# code.

Stars936
Forks99
Last commit3 months ago
Code ConverterCode Converter

Convert code from C# to VB.NET and vice versa using Roslyn

Stars904
Forks238
Last commit9 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub