Speeding Up Java
This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:
Firstly : Given an established Java project, what are some decent ways to speed it up beyond just plain in-code optimization?
Secondly : When writing a program from scratch in Java, what are some good ways to greatly improve performance?
Please stay away from general optimization techniques unless they are Java specific.
I asked this about Python and Perl earlier. For Java I'm wondering what good tips/tricks are out there to improve performance and if there are any particularly good Java profilers.
Firstly : by code optimization, I would assume that you've done the right algorithms and right implementation of algorithms. In which case, you would use the profiler and look at how often your garbage collector(GC) is collecting garbage and how much time it is using for doing that. Then you start working on the GC options -- but beware you can get into trouble if you don't know what you're doing.
I assume that you're using java 5/6. In which case, I'd go through the java 5 tuning guide at http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html. There is also a very very good newletter on java performance called http://www.javaperformancetuning.com/ to which you can subscribe.
Other than that, look at how many try/catch blocks you can eliminate. See if you can eliminate unnecessary throwing of Exceptions.
Use Caches where you can BUT don't over do it.
Read Effective Java, 1st and/or 2nd Edition
Profilers : I use yourkit. It's pretty good for java 1.5 and above. You can get a personal license. Other profilers are also good as well.
Just like you have unit and integration tests, it does NOt hurt to have some performance tests that you run as part of your CONTINUOUS INTEGRATION(CI) builds. This way you know when you regressed, especially if you are using a good CI build server.
确保您的日志级别不会在DEBUG上意外遗留下来:)
"Measure, don't guess."
Here is a good article on using the NetBeans Profiler to speed up the iText PDF library. I've used the NetBeans Profiler myself, and I've found it to be very easy and useful in tracking down some performance issues I was having.
For an older application, simply moving to Java 6 might be a performance boost. See this whitepaper for information on the performance improvements in Java 6.
链接地址: http://www.djcxy.com/p/6726.html上一篇: 关于过早优化的另一个问题
下一篇: 加速Java