Very easy to understand java application performance tuning skills sharing

Most developers take it for granted that performance optimization is complex and requires a lot of experience and knowledge. Well, it can't be said that this is completely wrong. Optimizing applications for optimal performance is not an easy task. But that doesn't mean you can't do anything without this knowledge. Here are 11 easy to follow suggestions and best practices to help you create a good performance application.

Most of the recommendations are for Java. However, a number of recommendations are language independent and can be applied to all applications and programming languages. Before discussing performance tuning techniques specifically for Java, let's take a look at general techniques.

1. Don't optimize until you know it's necessary

This is probably one of the most important performance tuning techniques. You should follow common best practices and try to implement use cases efficiently. However, this does not mean that you should replace any standard libraries or build complex optimizations before you prove necessary.

In most cases, premature optimization not only takes a lot of time, but also makes the code difficult to read and maintain. Worse, these optimizations usually don't bring any benefits, because you spend a lot of time optimizing non critical parts of the application.

So how do you prove that you need to optimize something?

First, you need to define how fast the application code is, for example, specify the maximum response time for all API calls, or specify the number of records to import within a specific time range. After that, you can measure which parts of the application are too slow to improve. Then, look at the second technique.

2. Use the analyzer to find the real bottleneck

After you follow the first suggestion and determine that some parts of the application need to be improved, where do you start?

You can solve the problem in two ways:

Look at your code and start with something that looks suspicious or you think might cause a problem. Or use the parser and get detailed information about the behavior and performance of each part of the code. I hope I don't need to explain why the second method should always be followed.

Obviously, an analyzer based approach can give you a better understanding of the performance impact of your code and enable you to focus on the most critical parts. If you have ever used an analyzer, you must remember how surprised you were to find out which parts of the code had performance problems. To be honest, my first guess led me to go in the wrong direction more than once.

3. Create a performance test suite for the entire application

This is another general technique that can help you avoid many unexpected problems that often occur after deploying performance improvements to production. You should always define a performance test suite to test the entire application and run it before and after performance improvement.

These additional test runs will help you identify the functional and performance side effects of changes and ensure that they do not lead to updates that do more harm than good. This is especially important if you work on components that are used by several different parts of the application, such as databases or caches.

4. Deal with the biggest bottleneck first

After creating the test suite and analyzing the application using the analyzer, you can list a series of problems that need to be solved to improve performance. That's good, but it still doesn't answer the question where you should start. You can focus on quick impact solutions or start with the most important issues.

Quick impact solutions can be attractive at first because you can quickly show the first result. But sometimes, you may need to convince other team members or management that performance analysis is worth it -- because you can't see the effect for the time being.

But in general, I suggest dealing with the most important performance issues first. This will provide you with the greatest performance improvement, and you may no longer need to solve some of these problems to meet performance requirements.

This concludes the common performance tuning techniques. Let's take a closer look at some Java specific techniques.

5. Use StringBuilder to connect strings programmatically

There are many different options for connecting strings in Java. For example, you can use simple + or + =, and StringBuffer or StringBuilder.

Since we are discussing data types, let's also take a quick look at BigInteger and BigDecimal. In particular, the latter is welcomed by everyone because of its accuracy. But there is a price.

10. Use Apache Commons stringutils Replace instead of string replace

Java implementation of wechat public platform circle of friends sharing function detailed code

Comparative analysis of Java Native serialization and kryo serialization performance examples

Exploration on whether the subclass of Java programming can override the static method of the parent class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>