[From the sandbox] .NET zoo under the prism of NET Core

[From the sandbox] .NET zoo under the prism of NET Core


Hello! Today we will look at the various chips and changes that appeared in the .NET Core platform and compare them with the Framework. I broke the article into modules for better understanding. This article will be interesting to those who are going to switch to .NET Core or are already using it.

Stack technology


We currently have three platforms: .NET Framework, Mono, and .NET Core. Each platform includes the following technologies:

NET Framework - WPF, WinForms, ASP.NET (DNX implementation), WCF
NET Core - UWP, ASP.NET Core, WA, Xamarin (.NET Standard), Avalonia and other
Mono - Xamarin (PCL, Share project), Unity, ASP.NET, WinForms (cross platform)
NET Core (3.0) - Everything is the same as the .NET Core above + WPF and WinForms, ML.NET

NET Standard


There is also a .NET Standard. This is a set of classes, methods and interfaces that allow you to write and use common code for all the platforms listed above. You can also write console applications on it. In short, this is the same PCL, but it works on all the platforms listed above.

Cross Platform


I will not draw your attention to this, I will simply list the support for the OS for NET Core projects:

Windows
Linux
MacOS

Additionally, it supports running on ARM processors on Linux and Windows.

Dependency


As part of cross-compatibility, the application development platform includes a modular infrastructure. It is issued via NuGet, and you can access the batch functions, rather than one large assembly. As a developer, you can create lightweight applications that contain only the necessary NuGet packages, which will make your program safer and more productive.

The modular infrastructure also allows for faster updates to the .NET Core platform, since affected modules can be updated and released separately.

CSPROJ


Now let's dive in and see in more detail what is under the hood in our projects. When creating a new project, each of you came across a file MyProject1.csproj (the name may differ). This file is responsible for the compilation settings of this project, dependencies of other projects or libs (libraries) and many more.

I have an example for you of how I decided to rewrite one project on .NET Standard. Let's take a look how it was before (Framework):



Unfortunately on my PC, this file does not fit completely (there are still references). And now let's take a look at what happened after the transfer:



In NET Core and .NET Standard, csproj has been greatly simplified. Particularly "ballistic" may notice that little has changed. I removed the unnecessary and replaced with more convenient tools. After rewriting csproj, I noticed that working with NuGet packages began to take noticeably less time and, as you understand, it is more convenient to edit the new version of csproj, because it is not cluttered with unnecessary lines.

Performance & amp; Improvements


Modified Random
Modified HttpClient
optimized cycles
Optimized List, Array
Optimized Stream, MemoryStream
and many more

In this article I will not consider all the changes. This will be a separate article. But let's look at a small example on the List collection:

  var list = new List & lt; int & gt; ();
 for (int i = 0; i & lt; 100000000; i ++)
 {
  list.Add (i);
  list.RemoveAt (0);
 }  

I drove it through benchmarkdotnet.org on both platforms. After the tests, I got the following results:

Core 2.2.4 x64 RyuJIT
Method : BenchmarkList
Mean : 370.1 ms
Error : 0.3761 ms
StdDev : 0.3518 ms

Framework 4.7.2 x64 RyuJIT
Method : BenchmarkList
Mean : 481.9 ms
Error : 1.210 ms
StdDev : 1.011 ms

As you can see, the speed of work is significantly different (at times) in favor of the Core.

Microsoft is trying not only to give developers convenient development tools, but also improves the basic things that lead to improvements and optimization of your projects.

Tier Compilation


This is a feature that makes the runtime more adaptively using the JIT compiler to improve startup performance and maximize throughput.
  & lt; Project Sdk = "Microsoft.NET.Sdk.Web" & gt;
  & lt; PropertyGroup & gt;
  & lt; TargetFramework & gt; netcoreapp2.2 & lt;/TargetFramework & gt;
  & lt; LangVersion & gt; 7.3 & lt;/LangVersion & gt;
  & lt;! - The next line is responsible for enabling this feature - & gt;
  & lt; TieredCompilation & gt; true & lt;/TieredCompilation & gt;
  & lt; Platforms & gt; AnyCPU; x64 & lt;/Platforms & gt;
  & lt;/PropertyGroup & gt;
 & lt;/Project & gt;  

Compiles a project as quickly as possible.

Optimizes the most common methods.

This functionality leads to the fact that your project is going faster and gives you almost the same performance. We tested this functionality, and this is a smart feature for NET Core projects, which reduces compile time. Multi-level compilation slightly slows down your application, I do not advise to enable it on the production server, but for debugging there is more than an actual feature that saves programmers time.

Conclusion


Microsoft is trying to improve the lives of developers. NET platform. All the listed “buns” that have appeared in our company allow us to make the environment more open and expandable. Hope you appreciate it. Do not be afraid to switch to a new technology stack and use different features.

Thank you for your attention. Hope you enjoyed it.

Source text: [From the sandbox] .NET zoo under the prism of NET Core