frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

“ZLinq”, a Zero-Allocation LINQ Library for .NET

https://neuecc.medium.com/zlinq-a-zero-allocation-linq-library-for-net-1bb0a3e5c749
76•cempaka•4h ago

Comments

incoming1211•3h ago
Is there a reason these sort of improvements cannot be contributed back into .NET itself?
bob1029•3h ago
I don't see why not: https://github.com/dotnet/runtime/pulls

There's an official process for API change requests: https://github.com/dotnet/runtime/blob/main/docs/project/api...

lmz•3h ago
I can easily imagine the kind of person that goes out and builds something like this would have little patience with the bureaucracy of getting it integrated into .NET.
CharlieDigital•3h ago
I'd say it's less about bureaucracy and more about what the .NET team has to consider when they make sweeping changes.

Backwards compatibility, security, edge cases, downstream effects on other libraries that are reliant on LINQ, etc.

One guy with an optional library can break things. If the .NET team breaks things in LINQ, it's going to be a bad, bad time for a lot of people.

I think Evan You's approach with Vue is really interesting. Effectively, they have set up a build pipeline that includes testing major downstream projects as well for compatibility. This means that when the Vue team build something like "Vapor Mode" for 3.6, they've already run it against a large body of community projects to check for breaking changes and edge cases. You can see some of the work they do in this video: https://www.youtube.com/watch?v=zvjOT7NHl4Q

mrmedix•3h ago
You have to add an extra function call at the start of the Linq method chain in order to make it zero-allocation. So I don't think it would break backwards compatibility. But adding it does create an additional maintenance burden.
akdev1l•3h ago
I think this approach predates Vue.

I know of two examples:

1. Fedora in collaboration with GCC maintainers keep GCC on the bleeding edge so it can be used to compile the whole Fedora corpus. This validates the compiler against a set of packages which known to work with the previous GCC

2. I think the rust team also builds all crates on crates.io when working on `rustc`. It seems they created a tool to achieve that: https://github.com/rust-lang/crater

I would assume the .NET guys have something similar already but maybe there’s not enough open code to do that

zamalek•2h ago
Rust also has the advantage of having no ABI. Binary interface is a whole lot more difficult to maintain than code interface.

C# has multiple technologies built to deal with ABI (though it probably all goes unused these days with folder-based deployments, you really need the GAC for it to work).

jasonjayr•50s ago
IIRC perl tested new releases by running all the unit tests in the CPAN library, waaaaay back when.
qingcharles•2h ago
From some experience, the MS guys are actually really eager to get more outside help and many will help guide you through the process if you have something to offer.

Every release has a fairly decent amount of fixes and additions from outside contributors, and while I can see a lot of to/fro on the PRs to get them through, it's probably not quite as bad as you'd expect.

nikeee•3h ago
ZLinq relies on its own enumerable type called ValueEnumerable, which is a struct. While it would probably work when using this as a drop-in replacement and re-compiling, things will be more complicated in larger applications. There might be some code that depends on the exact signature of the Linq methods. This might not even be detectable in cases involving reflection and could break stuff silently.

Adding another enumerable type would be a very large change that could effectively double the API surface of the entire ecosystem. This could take some time. Some places still don't even support Span<T>. Also there were some design decisions related to Linq where the number of overloads were a consideration.

Adding this API to .NET could probably be done with that extension method that converts to ValueEnumerable. But without support for that enumerable, this would pretty much be a walled garden where you have to convert back and forth between different enumerable types. Not that great if you'd ask me, but possible I guess.

kevingadd•1h ago
From looking at the blog post I suspect the explosion of generic instances could be a serious problem for code size and startup time, but that's probably solvable somehow. The performance certainly seems impressive.

The way LINQ currently works by default makes aggressive use of interfaces like IEnumerable to hide the actual types being iterated over. This has performance consequences (which is part of why ZLinq can beat it) but it has advantages - for example, the same implementation of Where<T>(seq) can be used for various T's instead of having to JIT or AOT-compile a unique body for every distinct class you iterate over.

From looking at ZLinq it seems like it would potentially have an explosion of unique generic struct types as your queries get more complex, since for it to work you potentially end up with types vaguely resembling Query3<Query2<Query1<T>>>>. But it might not actually be that bad in practice.

jasonthorsness•2h ago
This is great. I've worked on production .NET services and we often had to avoid LINQ in hot paths because of the allocations. Reimplementing functions with for-loops and other structures was time-consuming and error-prone compared to LINQ method chaining. Chaining LINQ methods is extremely powerful; like filter, map, and reduce in JS but with a bunch of other operators and optimizations. I wish more languages had something like it.
meisel•41m ago
What are the advantages of this over using higher order functions? In Ruby I can do list.map { }.select { } …. That feels more natural (doesn’t require special language support), has a very rich set of functions (group_by, chunk_while, etc.), and is something the user can extend with their own methods (if they don’t mind monkeypatching)
zamalek•2h ago
In theory .Net 10 should make this obsolete, the headline features[1] are basically all about this. In practice, well, it's heuristics, I'm adding this to a particularly performance sensitive project right now :)

Edit: what's also nice is that C# recognizes Linq as a contract. So long as this has the correct method names and signatures (it does), the Linq syntax will light up automatically. You can also use this trick for your own home-grown things (add Select, Join, Where, etc. overloads) if the Linq syntax is something you like.

[1]: https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotn...

Jordanpomeroy•1h ago
Could you elaborate? I don’t see anything about improving the performance of enumerator. Zlinq appears to remove the penalty of allocating enumerators on the heap to be garbage collected. The link you sent mention improvements, but I don’t see how they lead to linq avoiding heap allocations.
giancarlostoro•1h ago
Not just that but Zlinq also works across all C# environments it seems including versions embedded in game engines like Godot, Unity, .NET Standard, .NET 8 and 9.
kevingadd•1h ago
I believe they're referring to the stack allocation improvements, which would ideally allow all the LINQ temporary objects to live on the stack. I'm not sure whether it does in practice though.
andyayers•1h ago
Unfortunately, those improvements don't work for Linq.

Some notes on why this is so here: https://github.com/dotnet/runtime/blob/main/docs/design/core...

HexDecOctBin•2h ago
What features does C# has that makes LINQ possible in it and not in other languages?
sherburt3•2h ago
I feel like pretty much every language with generics has a LINQ, like functools/itertools in Python, lodash for javascript. It’s just a different expression of the same ideas.
jeswin•1h ago
Nope, very different. Depending on whether the expression is on an Enumerable or a Queryable, the compiler generates an anonymous function or an AST. That is, you can get "code as data" as in say Lisp; and allows expressions to be converted to say SQL based on the backend.
tehlike•2h ago
It's part of the compiler - ast. Linq has two forms - one in the linq ordinary syntax

from x select x.name

And other is just lambda with anonymous types and so on.

For the lambda syntax, you can just do this: https://www.npmjs.com/package/linq

Of course, if you want to run this against a query provider, you do need compiler support to instead give you an expression tree, and provider to process it and convert them to a language (often sql) that database can understand.

There seems to be some transpilers, or things like that - but i don't know what the state of the art is on this: https://github.com/sinclairzx81/linqbox

Merad•56m ago
Basic LINQ on in-memory collections isn't really that different from what you have in other languages. Where things get special is the LINQ used by Entity Framework. It operates on expressions, which allow code to be compiled into the application and manipulated at runtime. For example, the lambda expression that you pass to Where() will be examined by an EF query provider that translates it into the where clause for a SQL query.
osigurdson•39m ago
I get that Go maintainers want to keep things simple, but this stuff is pretty useful.
bigmattystyles•2h ago
This is cool - excited to try it - I would note that I've been a dotnet grunt for almost 15 years now. I am good at it, I know how to use the language, I know the ecosystem - this level of familiarity with the language is just not within my grasp. I can understand the code (mostly) reading it, but I never would have been able to conjure up, let alone implement this. Props to the author.
KallDrexx•41m ago
This is neat, but how does this get away with being zero allocation? It appears to use `Func<T,U>` for its predicates, and since `Func<T>` is a reference type this will allocate. The IL definitely generates definitely seems like it's forming a reference type from what I can tell.
ziml77•32m ago
The JIT can optimize this. I know for sure if there's no captures in the lambda it won't allocate. It's likely also smart enough to recognize when a function parameter doesn't have its lifetime extended past the caller's, which is a case where it would also be possible to not allocate.

Teen swimmer caught in rip current rescued by drone [video]

https://www.youtube.com/watch?v=CdGxAbDFQDQ
1•handfuloflight•34s ago•0 comments

Build with Jules, your asynchronous coding agent

https://blog.google/technology/google-labs/jules/
1•badmonster•1m ago•0 comments

Code Improvement Practices at Meta (2025)

https://arxiv.org/abs/2504.12517
1•Gigacore•1m ago•0 comments

Relume

https://www.relume.io/
1•handfuloflight•3m ago•0 comments

Ask HN: Trivial things that you have weirdly strong opinions about

1•kaycebasques•8m ago•0 comments

Magnus Carlsen forced into a draw by more than 143000 people playing against him

https://apnews.com/article/chess-magnus-carlsen-match-world-freestyle-grandmaster-963a977765fa02d05a14d701666dfcd7
3•namanyayg•8m ago•0 comments

Good Design Comes from Looking, Great Design Comes from Looking Away

https://www.chrbutler.com/good-design-comes-from-looking-great-design-comes-from-looking-away
1•MBCook•8m ago•0 comments

A broken thruster jeopardized Voyager 1, but engineers executed a remote fix

https://www.npr.org/2025/05/20/nx-s1-5403501/voyager-thruster-nasa-interstellar
1•namanyayg•8m ago•1 comments

Waymo says it reached 10M robotaxi trips, doubling in five months

https://www.cnbc.com/2025/05/20/waymo-ceo-tekedra-mawakana-10-million.html
2•carbocation•9m ago•0 comments

The Agentic Web and Original Sin

https://stratechery.com/2025/the-agentic-web-and-original-sin/
1•VignuB•11m ago•0 comments

AI could keep us dependent on natural gas for decades to come

https://www.technologyreview.com/2025/05/20/1116272/ai-natural-gas-data-centers-energy-power-plants/
1•kawera•11m ago•0 comments

AI in Search: Going beyond information to intelligence

https://blog.google/products/search/google-search-ai-mode-update/
1•ruidlopes•11m ago•0 comments

You Won't Learn This in School: Disabling Kernel Functions in Your Process(2009)

https://chadaustin.me/2009/03/disabling-functions/
1•rolph•15m ago•0 comments

The data center boom in the desert

https://www.technologyreview.com/2025/05/20/1116287/ai-data-centers-nevada-water-reno-computing-environmental-impact/
1•gnabgib•17m ago•0 comments

Gemma 3n

https://deepmind.google/models/gemma/gemma-3n/
1•mromanuk•20m ago•1 comments

Firebase MCP Server

https://firebase.blog/posts/2025/05/firebase-mcp-server/
1•LyalinDotCom•20m ago•0 comments

Ask HN: Are AI Agents a Lie?

1•David1238•20m ago•1 comments

The unlikely rise of the Indian space program [video]

https://www.youtube.com/watch?v=8jQzwxS8vxA
1•namanyayg•21m ago•0 comments

Windows ML: The future of machine learning development on Windows

https://blogs.windows.com/windowsdeveloper/2025/05/19/introducing-windows-ml-the-future-of-machine-learning-development-on-windows/
2•T-A•23m ago•0 comments

A Secret Trove of Rare Guitars Heads to the Met

https://www.newyorker.com/magazine/2025/05/26/a-secret-trove-of-rare-guitars-heads-to-the-met
8•bookofjoe•24m ago•1 comments

Show HN: Interactive AI vibe analysis and edit agent for connected data

https://www.trynexus.io
1•nikhilpil•24m ago•0 comments

New Microbe Discovered Aboard Chinese Space Station

https://www.newsweek.com/new-microbe-chinese-space-station-2074452
2•freedomben•25m ago•0 comments

Adreno Control Panel for Devices with Snapdragon X Elite

https://www.qualcomm.com/developer/blog/2025/05/introducing-adreno-control-panel-snapdragon-x-elite-2025-1-beta
1•xgdgsc•26m ago•0 comments

Wolfspeed prepares to file for bankruptcy within weeks

https://www.reuters.com/business/wolfspeed-prepares-file-bankruptcy-within-weeks-wsj-reports-2025-05-20/
2•jand•30m ago•0 comments

Practical AI techniques for daily engineering work

https://www.seangoedecke.com/practical-ai-techniques/
1•swah•30m ago•0 comments

Show HN: Gen-ts-type – Code Generate TS Type from JSON data with collapsed field

https://gen-ts-type.surge.sh
1•aabbcc1241•34m ago•0 comments

Mice use chemical cues such as odours to sense social hierarchy

https://www.crick.ac.uk/news/2025-05-19_mice-use-chemical-cues-such-as-odours-to-sense-social-hierarchy
1•gnabgib•39m ago•0 comments

Obesity and Efforts to Lose Weight (1992)

https://www.nejm.org/doi/10.1056/NEJM199212313272710
1•paulpauper•41m ago•0 comments

Fat 'remembering' past obesity drives yo-yo diet effect, say experts

https://www.theguardian.com/society/2024/nov/18/ability-fat-remember-obesity-drives-yo-yo-diet-effect
4•paulpauper•44m ago•1 comments

Has AI generated a new treatment for blindness?

https://twitter.com/sgrodriques/status/1924845624702431666
3•paulpauper•45m ago•1 comments