πŸ‡¨πŸ‡¦VancouverπŸ‡¨πŸ‡¦TorontoπŸ‡ΊπŸ‡ΈLos AngelesπŸ‡ΊπŸ‡ΈOrlandoπŸ‡ΊπŸ‡ΈMiami
1-855-KOO-TECH
KootechnikelKootechnikel
Insights Β· Field notes from the SOC
Plain-language briefings from the people watching the alerts.
Weekly Β· No spam
Back to News
Developer Tooling & Software EngineeringIndustry

ZLinq Zero-Allocation LINQ Library Released for .NET

AuthorZe Research Writer
Published
Read Time6 min read
Views0
ZLinq Zero-Allocation LINQ Library Released for .NET

ZLinq Zero-Allocation LINQ Library Released for .NET

Yoshifumi Kawai released ZLinq v1, a zero-allocation LINQ library for .NET that uses structs and generics to eliminate heap allocations, with extensions for Span, SIMD, and tree traversal operations.

Yoshifumi Kawai, a developer known for creating high-performance .NET libraries, released ZLinq v1 in April 2025. The library provides a zero-allocation alternative to the standard LINQ (Language Integrated Query) implementation in .NET. By building on structs and generics rather than classes and interfaces, ZLinq eliminates heap allocations that occur during typical LINQ operations.

Technical diagram showing vulnerability chain
Figure 1: Visual representation of the BeyondTrust vulnerability chain

What Happened

Kawai published a detailed technical article on Medium on May 15, 2025, explaining the design decisions and implementation details behind ZLinq. The article, which runs approximately 15 minutes in reading time, covers the struct-based architecture that enables zero allocations.

The library originated from the Cysharp organization, which Kawai founded to develop high-performance .NET tools. According to the GitHub repository, the project was initially created in October 2014 but received significant updates leading to the v1 release in April 2025.

On May 20, 2025, the project gained substantial visibility on Hacker News, where it accumulated 269 points and generated 88 comments from the developer community. The discussion centered on performance comparisons with standard LINQ and practical use cases in production environments.

Key Claims and Evidence

According to Kawai's Medium article, ZLinq achieves zero allocations by using structs instead of classes for iterator implementations. Standard LINQ creates iterator objects on the heap for each operation in a query chain, leading to garbage collection overhead. ZLinq's struct-based approach keeps these iterators on the stack.

The library's GitHub description states it provides "Zero allocation LINQ with LINQ to Span, LINQ to SIMD, and LINQ to Tree." The repository documentation indicates support for .NET Standard 2.0, .NET Standard 2.1, .NET 6, .NET 8, and .NET 9, along with Unity 2021.3 and later versions.

Benchmark data presented in the documentation shows significant performance improvements over standard LINQ for common operations like Where, Select, and aggregate functions. The exact performance gains vary by operation type and data size.

Authentication bypass flow diagram
Figure 2: How the authentication bypass vulnerability works

Pros and Opportunities

Developers working on latency-sensitive applications can reduce garbage collection pauses by eliminating allocations in query operations. Game developers using Unity or Godot gain access to LINQ-style syntax without the performance penalties that typically make LINQ unsuitable for frame-critical code paths.

The LINQ to Span extension enables efficient processing of stack-allocated arrays and memory slices, which proves valuable for parsing and data transformation tasks. LINQ to SIMD allows developers to leverage CPU vector instructions through familiar LINQ syntax.

The MIT license permits commercial use without restrictions, and the library's compatibility with multiple .NET versions reduces adoption barriers for existing projects.

Cons, Risks, and Limitations

The struct-based design introduces complexity that developers must understand to use the library effectively. Structs in .NET have different copying semantics than classes, and improper use can lead to unexpected behavior or performance degradation.

Some Hacker News commenters noted that the library requires developers to learn new patterns and may not provide benefits for applications where LINQ performance is not a bottleneck. The additional cognitive overhead may not justify the performance gains in all scenarios.

The library's API differs from standard LINQ in certain areas, meaning existing code cannot simply swap implementations without modification. Migration requires careful testing to ensure behavioral equivalence.

Privilege escalation process
Figure 3: Privilege escalation from user to SYSTEM level

How the Technology Works

Standard LINQ in .NET uses interfaces like IEnumerable<T> and creates class-based iterator objects for each operation. When a developer chains multiple LINQ operations, each operation allocates a new iterator object on the managed heap. These allocations eventually require garbage collection, which can cause latency spikes in performance-critical applications.

ZLinq replaces these class-based iterators with struct-based implementations. Structs in .NET are value types that typically reside on the stack rather than the heap. By using generics extensively, ZLinq can chain operations without heap allocations while maintaining type safety.

The LINQ to Span extension works with Span<T> and ReadOnlySpan<T>, which represent contiguous regions of memory. Standard LINQ cannot operate on spans because spans are ref structs with stack-only semantics. ZLinq's architecture accommodates these constraints.

LINQ to SIMD leverages the System.Numerics.Vector types to perform operations on multiple data elements simultaneously. The library translates LINQ-style queries into vectorized operations where applicable.

Technical context for expert readers: The struct-based approach requires careful handling of the "boxing" problem, where value types converted to interface references allocate on the heap. ZLinq avoids this through generic constraints and specialized implementations that never require boxing.

Industry Implications

The release reflects ongoing efforts in the .NET ecosystem to provide high-performance alternatives to convenient but allocation-heavy APIs. Microsoft has invested significantly in reducing allocations in .NET itself, and community libraries like ZLinq extend this work to areas the framework does not address directly.

Game development frameworks increasingly target .NET, with Unity using a modified Mono runtime and Godot offering C# as a scripting option. Libraries that enable idiomatic .NET code without performance penalties support this trend.

The approach ZLinq takes, using structs and generics to eliminate allocations, has influenced other library designs in the .NET ecosystem. Similar patterns appear in serialization libraries, collection implementations, and parsing frameworks.

Confirmed Facts and Open Questions

Confirmed:

  • ZLinq v1 released in April 2025 by Yoshifumi Kawai
  • Library uses struct-based iterators to achieve zero allocations
  • Supports .NET Standard 2.0/2.1, .NET 6/8/9, Unity 2021.3+, and Godot
  • Licensed under MIT
  • GitHub repository has over 4,800 stars as of May 20, 2025

Unclear:

  • Specific performance benchmarks across different workload types
  • Adoption rates in production environments
  • Compatibility with all existing LINQ extension methods from third-party libraries

What to Watch Next

The .NET community's adoption of ZLinq in production applications will indicate whether the performance benefits outweigh the migration costs. Unity and Godot game developers represent a particularly relevant audience given their sensitivity to garbage collection.

Future .NET versions may incorporate similar optimizations into the standard library, potentially reducing the need for alternative implementations. Microsoft's ongoing work on performance improvements in .NET 10 and beyond bears monitoring.

The Cysharp organization's other projects, including MessagePack for C# and UniTask, have achieved significant adoption. ZLinq's trajectory may follow similar patterns if it proves valuable in real-world scenarios.

Sources & References

Related Topics

dotnetlinqperformancememory-allocationopen-source