Reader small image

You're reading from  C# 7 and .NET Core 2.0 High Performance

Product typeBook
Published inApr 2018
Reading LevelBeginner
Publisher
ISBN-139781788470049
Edition1st Edition
Languages
Right arrow
Author (1)
Ovais Mehboob Ahmed Khan
Ovais Mehboob Ahmed Khan
author image
Ovais Mehboob Ahmed Khan

Ovais Mehboob Ahmed Khan is a seasoned programmer and solution architect with nearly 20 years of experience in software development, consultancy, and solution architecture. He has worked with various clients across the world and is currently working as a senior customer engineer at Microsoft. He specializes mainly in application development using .NET and OSS technologies, Microsoft Azure, and DevOps. He is a prolific writer who has written several books and articles on various technologies. He really enjoys talking about technology and has given a number of technical sessions around the world.
Read more about Ovais Mehboob Ahmed Khan

Right arrow

Understanding .NET Core Internals and Measuring Performance

When developing application architecture, knowing the internals of how the .NET framework works plays a vital role in ensuring the quality of the application's performance. In this chapter, we will focus on the internals of .NET Core that can help us write quality code and architecture for any application. This chapter will cover some of the core concepts of .NET Core internals, including the compilation process, garbage collection, and Framework Class Library (FCL). We will complete this chapter by going through the BenchmarkDotNet tool, which is mostly used in measuring code performance, and is highly recommended for benchmarking code snippets within an application.

In this chapter, you will learn the following topics:

  • .NET Core internals
  • Utilizing multiple cores of the CPU for high performance
  • How releasing builds...

.NET Core internals

.NET Core contains two core components—the runtime CoreCLR and the base-class libraries CoreFX. In this section, we will cover the following topics:

  • CoreFX
  • CoreCLR
  • Understanding MSIL, CLI, CTS, and CLS
  • How CLR works
  • From compilation to execution—under the hood
  • Garbage collection
  • .NET Native and JIT compilation

CoreFX

CoreFX is the code name of .NET Core's set of libraries. It contains all the libraries that start with Microsoft.* or System.*and contains collections, I/O, string manipulation, reflection, security, and many more features.

The CoreFX is runtime agnostic, and it can run on any platform regardless of what APIs it supports.

To learn more about each assembly, you can refer...

Utilizing multiple cores of the CPU for high performance

These days, the nature of applications focuses more on connectivity, and there are cases where their operations take more time to execute. We also know that nowadays, all computers come with a multi-core processor, and using these cores effectively increases the performance of the application. Operations such as network/IO have latency issues, and the synchronous execution of the application program may often lead to a long waiting time. If the long-running tasks are executed in a separate thread or in an asynchronous manner, the resulting operation will take less time and increase responsiveness. Another benefit is performance that actually utilizes multiple cores of the processor and executes the task simultaneously. In the .NET world, we can achieve responsiveness and performance by splitting the tasks into multiple threads...

How releasing builds increases performance

Release and debug builds are two build modes provided in .NET applications. Debug mode is mostly used when we are in the process of writing code or troubleshooting errors, whereas release build mode is often used while packaging the application to deploy on production servers. When developing the deployment package, developers often miss updating the build mode to the release build, and then they face performance issues when the application is deployed:

The following table shows some differences between the debug and release modes:

Debug

Release

No optimization of code is done by the compiler

Code is optimized and minified in size when built using release mode

Stack trace is captured and thrown at the time of exception

No stack trace is captured

The debug symbols are stored

All code and debug symbols under #debug...

Benchmarking .NET Core 2.0 applications

Benchmarking applications is the process of evaluating and comparing artifacts with the agreed upon standards. To benchmark .NET Core 2.0 application code, we can use the BenchmarkDotNet tool, which provides a very simple API to evaluate the performance of code in your application. Usually, benchmarking at the micro-level, such as with classes and methods, is not an easy task, and requires quite an effort to measure the performance, whereas BenchmarkDotNet does all the low-level plumbing and the complex work associated with benchmark solutions.

Exploring BenchmarkDotNet

In this section, we will explore BenchmarkDotNet and learn how effectively it can be used to measure application performance...

Summary

In this chapter, we have learned about the core concepts of .NET Core, including the compilation process, garbage collection, how to develop high-performant .NET Core applications by utilizing multiple cores of the CPU, and publishing an application using a release build. We have also explored the benchmarking tool, which is highly used for code optimization, and provides results specific to class objects.

In the next chapter, we will learn about multithreading and concurrent programming in .NET Core.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
C# 7 and .NET Core 2.0 High Performance
Published in: Apr 2018Publisher: ISBN-13: 9781788470049
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ovais Mehboob Ahmed Khan

Ovais Mehboob Ahmed Khan is a seasoned programmer and solution architect with nearly 20 years of experience in software development, consultancy, and solution architecture. He has worked with various clients across the world and is currently working as a senior customer engineer at Microsoft. He specializes mainly in application development using .NET and OSS technologies, Microsoft Azure, and DevOps. He is a prolific writer who has written several books and articles on various technologies. He really enjoys talking about technology and has given a number of technical sessions around the world.
Read more about Ovais Mehboob Ahmed Khan