. NET program's Performance Essentials and optimization recommendations

Source: Internet
Author: User

Provides recommendations for performance optimizations that come from using managed code to rewrite C # and VB compilers, and to demonstrate these optimizations by writing some real-world scenarios in the C # compiler. The. NET platform is highly productive in developing applications. The powerful and secure programming language on the platform and the rich library of classes make developing applications effective. But the greater the capacity the greater the responsibility. We should use. NET Framework, but at the same time we need to be prepared to tune our code if we need to process large amounts of data such as files or databases.

Why the performance tuning experience from the new compiler is also applicable to your application

Microsoft uses managed code to rewrite the compilers of C # and Visual Basic, and to provide a list of new APIs for Code modeling and analysis, and for developing compilation tools that enable Visual Studio to have a richer code-aware programming experience. Rewriting the compiler, and the experience of developing Visual Studio on the new compiler, gives us a very useful experience with performance optimizations that can be used in large-scale applications. NET app, or some app that needs to handle a lot of data. You don't need to know about compilers, but you can also derive these insights from the example of the C # compiler.

Visual Studio uses the compiler's API to implement powerful IntelliSense features such as code keyword coloring, syntax fill lists, error wavy hints, parameter hints, code issues, and suggestions for modifications, which are popular with developers. Visual Studio dynamically compiles the code to gain analysis and hints for the code as the developer enters or modifies the code.

When users interact with the app, they usually want the software to be responsive. When entering or executing a command, the application interface should not be blocked. Help or hints can be displayed quickly or stop prompting when the user continues to enter. Today's app should avoid blocking the UI thread while performing long-time calculations to make the user feel that the program is not fluent.

To learn more about the new compiler, you can access the. NET Compiler Platform ("Roslyn")

Basic Essentials

Consider these basic essentials when you are tuning for. NET performance and developing well-responsive applications:

Essentials One: Don't optimize early

Writing code is much more complex than you might think, and the code needs to be maintained, debugged, and optimized for performance. An experienced programmer is usually a natural way of proposing a problem-solving approach and writing efficient code. But sometimes it's possible to get caught up in the problem of prematurely optimizing code. For example, sometimes it is enough to use a simple array, not to be optimized to use a hash table, and sometimes a simple recalculation can be done, rather than using a complex cache that could cause a memory leak. When you find a problem, you should first test the performance issue and then analyze the code.

Essentials Two: No evaluation, is guessing

Anatomy and measurement do not lie. The evaluation can show whether the CPU is running at full capacity or if there is disk I/O blocking. The assessment tells you what and how much memory the application allocates, and whether the CPU spends a lot of time on garbage collection.

You should set performance targets for critical user experiences or scenarios, and write tests to measure performance. The steps to analyze the causes of performance nonconformities by using a scientific approach are as follows: Use the evaluation report to guide, assume what might happen, and write experimental code or modify the code to validate our assumptions or corrections. If we set basic performance metrics and often test, we can avoid some changes that lead to performance rollback (regression), which avoids wasting time in unnecessary changes.

Essentials Three: Good tools are important

Good tools enable us to quickly navigate to the biggest factors that affect performance (CPU, memory, disk) and to help us locate the code that produces these bottlenecks. Microsoft has released a number of performance testing tools such as Visual Studio Profiler, Windows Phone analysis tool, and PerfView.

Perfview is a free and powerful tool that focuses on some of the deep-seated issues that affect performance (disk I/O,GC events, memory), which are shown later in this example. We are able to crawl performance-related event tracing for Windows (ETW) events and can view this information in the scale of applications, processes, stacks, and threads.


. NET program's Performance Essentials and optimization recommendations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.