Are there benefits in producing a .NET 6.0 version of a .NET Standard 2.0 library?
Asked Answered
H

1

8

If I have a .NET Standard 2.0 library project that is being consumed by a .NET 6.0 console project, are there any performance benefits if I also instruct the compiler to produce a .NET 6.0 version of the library?

I don't plan to use any functionality available on .NET 6.0, I just want to know if the .NET 6.0 version receives extra-love from the compiler.

Hanleigh answered 19/1, 2022 at 22:56 Comment(1)
I was wondering about this question in a more general sense: If I have a solution with 200 .NET Standard/.NET FW projects, do I need to upgrade all of them or just the startup project?Please
H
12

Asked the same thing on Twitter, and was fortunate enough to receive feedback from reputed experts Bartosz Adamczewski, Immo Landwerth, Jared Parsons and Lucas Trzesniewski

Here is the question link.

Here are the most relevant bits of info you can extract from the original Twitter thread:

What you might gain is better IL, so things like strings and certain other things are handled better by the front-end compiler C# and better IL is generated, this, in turn, could provide better codegen in JIT - Bartosz Adamczewski

@jaredpar can correct me but for the most part the code gen isn’t depending on the target framework, except for cases where the code gen users specific APIs, which is rare. - Immo Landwerth

That is correct. At the compiler level there is no concept of target frameworks, there are just references. Hence all decisions about code gen are based on the API in the references. - Jared Parsons

In the case of .NET 6, you'll get access to some new APIs such as DefaultInterpolatedStringHandler, so for instance all of your string interpolation expressions ($"...") will get a perf boost just by targeting net6.0. Also, there are new method overloads such as StringBuilder.Append that take string interpolation handlers as parameters. Your string interpolation expressions will target these instead when targeting net6.0, and your code will allocate less than on other targets. So yes, in some cases, your code will get more love by the compiler if you add a net6.0 target 🙂 - Lucas Trzesniewski

Hanleigh answered 16/5, 2022 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.