DEV Community

Matteo Maggiolini
Matteo Maggiolini

Posted on

some cool improvements introduced in .NET 8

dotnet publish and dotnet pack Release Mode: The dotnet publish and dotnet pack commands now build and pack with the Release mode by default. To produce in Debug mode, you need to set the parameter -p:PublishRelease as false.

System.Text.Json Serialization: Several enhancements have been made to object serialization and deserialization. The source generator now offers improved performance and reliability for Native AOT apps when used with ASP.NET Core. It also allows serializing types with required and init properties already supported in reflection-based serialization. There is now an option to customize the handling of members that are not present in the JSON payload. Support for serializing properties from interface hierarchies has been added. The JsonNamingPolicy feature has been expanded to include new naming policies for snake_case and kebab-case property name conversions. JsonSerializerOptions.MakeReadOnly method allows for explicit control over when a JsonSerializerOptions instance is frozen, and you can check its status using the IsReadOnly property.

Randomness: Two new methods, Random.GetItems and RandomNumberGenerator.GetItems, have been introduced that enable developers to randomly select a set number of items from a given input set. If you need to randomize the order of a span in your application, you can take advantage of two new methods: Random.Shuffle and RandomNumberGenerator.Shuffle.

Performance Improvements: Various new types have been introduced to enhance application performance. The System.Collections.Frozen namespace in .NET 8 includes the FrozenDictionary and FrozenSet collection types. These types are designed to prevent changes to keys and values once a collection is created, resulting in faster read operations such as TryGetValue(). They are particularly useful for collections populated on first use and then persisted for a long-lived service. Buffers.IndexOfAnyValues is a new type in .NET 8, designed to be passed to methods that search for the first occurrence of any value in a passed collection. Text.CompositeFormat is a new type in .NET 8 useful for optimizing format strings that aren't known at compile time.

Improvements in System.Numerics and System.Runtime.Intrinsics: Enhancements have been made to the System.Numerics and System.Runtime.Intrinsics namespaces, including better hardware acceleration for Vector256, Matrix3x2, and Matrix4x4 in .NET 8. Vector256 was redesigned to utilize 2x Vector128 operations internally to achieve partial acceleration of certain functions on Arm64 processors. The introduction of Vector512 is also included in .NET 8. The ConstExpected attribute has been added to hardware intrinsic to alert users when a non-constant value might cause unexpected performance issues. The Lerp(TSelf, TSelf, TSelf) API has been added to IFloatingPointIeee754, enabling the efficient and accurate linear interpolation of two values in float(Single), double (Double), and Half.

New Data Validation Attributes: The DataAnnotations namespace has been expanded with new attributes aimed specifically for validation in cloud-native services. These new attributes are meant to validate data, not entered by users, like configuration options. Apart from the new attributes, the RangeAttribute and RequiredAttribute types also received new properties.

Function Pointers Introspection Support: Function pointers were released with .NET 5. In .NET 8, a System.Type object is returned instead when using typeof or reflection on a function pointer, providing access to function pointer metadata, such as calling conventions, return type, and parameters.

Native AOT: The option to publish an application as native AOT enables the creation of a self-contained version of the app that does not require a separate runtime, bundling everything into a single file. In .NET 8, the support for native AOT now encompasses the x64 and Arm64 architectures on macOS. Moreover, native AOT applications on Linux are now up to 50% smaller in size.

Code Generation Improvements: .NET 8 includes enhancements to code generation and just-in-time (JIT) compilation, including JIT throughput improvements, Arm64 performance improvements, Profile-guided optimization (PGO) improvements, support for AVX-512 ISA extensions, SIMD improvements, cloud-native improvements, and loop and general optimizations.

.NET 8 DevOps Improvements: There are some changes with .NET 8 on image containers. Debian 12 is the default Linux distribution in the container images. The images include a non-root user to make the images non-root capable. The default port has also changed from 80 to 8080 and a new environment variable ASPNETCORE_HTTP_PORTS is available to change ports easily. .NET 8 is now supported on Chiseled Ubuntu images, available at the Ubuntu/DotNet-deps Docker Hub. Chiseled images are designed to have a smaller attack surface as they are stripped down to be ultra-compact, and do not include a package manager or shell. Chiseled images are non-root, making them ideal for developers looking for the benefits of appliance-style computing.

Building Your .NET on Linux: In .NET 8, you can build .NET directly on Linux using dotnet/source-build to create runtimes, tools, and SDKs. Red Hat and Canonical also use this build for .NET. Building in a container is the easiest approach for most people since the dotnet-buildtools/prereqs container images have all the necessary dependencies.

Minimum support baselines for Linux: The support requirements for Linux have been updated for .NET 8, with changes to the minimum support baselines. All architectures will target Ubuntu 16.04 for building .NET. Red Hat Enterprise Linux 7 is no longer supported with .NET 8. Only supporting RHEL 8 and later.

Top comments (0)