Cysharp / ZLinq
Zero allocation LINQ with LINQ to Span, LINQ to SIMD, and LINQ to Tree (FileSystem, JSON, GameObject, etc.) for all .NET platforms and Unity, Godot.
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing Cysharp/ZLinq in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewZLinq === Zero allocation LINQ with LINQ to Span, LINQ to SIMD, and LINQ to Tree (FileSystem, JSON, GameObject, etc.) for all .NET platforms(netstandard2.0, 2.1, net8, net9) and Unity, Godot. Unlike regular LINQ, ZLinq doesn't increase allocations when adding more method chains, and it also has higher basic performance. You can check various benchmark patterns at GitHub Actions/Benchmark. ZLinq shows high performance in almost all patterns, with some benchmarks showing overwhelming differences. As a bonus, LINQ operators and optimizations equivalent to .NET 10 can be used in .NET Framework 4.8 (netstandard2.0) and Unity (netstandard2.1). • **99% compatibility** with .NET 10's LINQ (including new , , , , operators) • **Zero allocation** for method chains through struct-based Enumerable via • **LINQ to Span** to full support LINQ operations on using .NET 9/C# 13's • **LINQ to Tree** to extend tree-structured objects (built-in support for FileSystem, JSON, GameObject) • **LINQ to SIMD** to automatic application of SIMD where possible and customizable arbitrary operations • Optional **Drop-in replacement** Source Generator to automatically accelerate all LINQ methods In ZLinq, we have proven high compatibility and performance by running dotnet/runtime's System.Linq.Tests as a drop-in replacement, passing 9000 tests. Previously, value type-based LINQ implementations were often experimental, but ZLinq fully implements all methods to completely replace standard LINQ in production use, delivering high performance suitable even for demanding applications like games. The performance aspects are based on my experience with previous LINQ implementations (linq.js, SimdLinq, UniRx, R3), zero-allocation implementations (ZString, ZLogger), and high-performance serializers (MessagePack-CSharp, MemoryPack). ZLinq achieves zero-allocation LINQ implementation using the following structs and interfaces. Besides changing to a struct-based approach, we've integrated MoveNext and Current to reduce the number of iterator calls. Also, some operators don't need to hold Current, which allows minimizing the struct size. Additionally, being struct-based, we efficiently separate internal state by copying the Enumerator instead of using GetEnumerator. With .NET 9/C# 13 or later, enables natural integration of into LINQ. TryGetNonEnumeratedCount(out int count) TryGetSpan(out ReadOnlySpan span) TryCopyTo(Span destination, Index offset) TryCopyTo ToArray TryGetNonEnumeratedCount First Last ElementAt TryCopyTo using ZLinq; AsValueEnumerable() AsValueEnumerable() AsValueEnumerable() IEnumerable IEnumerable .GetEnumerator() T[] List ArraySegment Memory ReadOnlyMemory ReadOnlySequence Dictionary Queue Stack LinkedList HashSet ImmutableArray Span ReadOnlySpan ImmutableArray .NET 8 Span ReadOnlySpan .NET 9 IEnumerable ICollection T[] List ZLinq T[] List System.Collections.IEnumerable AsValueEnumerable() ValueEnumerable AsValueEnumerable () ValueEnumerable.Range() ValueEnumerable.Repeat() ValueEnumerable.Empty() ValueEnumerable.Range ZLinq Enumerable.Range().AsValueEnumerable() Repeat Empty INumber DateTime Sequence InfiniteSequence Sequence InfiniteSequence INumber INumber .NET 7 ZLinq INumber byte/sbyte/ushort/char/short/uint/int/ulong/long/float/double/decimal DateTime DateTimeOffset Average() : where INumber Sum() : where INumber Average Sum INumber .NET 8 SumUnchecked() Sum checked SumUnchecked .NET 8 sbyte short int long byte ushort uint ulong double TryGetSpan AggregateBy CountBy AggregateBy CountBy TKey : notnull int CopyTo(Span destination) void CopyTo(List list) CopyTo ToArray ToList int CopyTo(Span destination) void CopyTo(List list) PooledArray ToArrayPool() ArrayPool .Shared PooledArray .Span .Memory .AsEnumerable() ValueEnumerable .AsValueEnumerable() ZLinq IDisposable ArrayPool .Shared using PooledArray struct ToArrayPool() using Deconstruct (T[] Array, int Size) PooledArray JoinToString(char|string separator) ZLinq IEnumerable String.Join JoinToString String.Join Enumerable.Sequence Enumerable.InfiniteSequence INumber IAdditionalOperator Sequence InfiniteSequence byte/sbyte/ushort/char/short/uint/int/ulong/long/float/double/decimal Range INumber Range Sequence InfiniteSequence DateTime DateTimeOffset ValueEnumerable ref struct IEnumerable AsEnumerable ValueEnumerable IEnumerable IEnumerable ToArray() ToArrayPool IEnumerable IEnumerable String.Join IEnumerable params object[] ValueEnumerable object[] JoinToString ValueEnumerable ValueEnumerable ref struct Concat Sum Average double ZLinq.DropInGenerator AsValueEnumerable() ZLinq generateNamespace DropInGenerateTypes DropInGenerateTypes Array Span Memory List Enumerable DropInGenerateTypes.Array | DropInGenerateTypes.Span Collection = Array | Span | Memory | List Everything = Array | Span | Memory | List | Enumerable DropInGenerateTypes.Enumerable IEnumerable generateNamespace Enumerable csharp using ZLinq; [assembly: ZLinqDropInAttribute("MyApp", DropInGenerateTypes.Everything)] // namespace under MyApp namespace MyApp.Foo { public class Bar { public static void Foo(IEnumerable source) { // ZLinq ValueEnum _...truncated for preview_