optimising : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

optimising
Introduction A Touch of Cynicism
Wise Thoughts Garbage Collection
How to Proceed Compiler and Run Time Optimisation
What Not To Do Books
General Tips Links

Introduction

Optimising, sometimes called tuning or fine tuning is the art of making computer programs run faster. It is also the art of finding the optimum tradeoffs between ease of maintenance, simplicity, terseness, speed, portability, low RAM (Random Access Memory) usage and quickness to get the app working in the first place. Don’t go crazy with optimisation. If you spend an extra man-week on a project optimising, over the lifetime of the project, you had better save at least a man-week of other people’s time waiting for the program, and you must consider that you have deprived those same people of using your program a week earlier.

Further, the cost of programmer time is rising and the cost of hardware is dropping. Spending time on optimising is less and less justifiable over time. However, it is often possible with a single tweak to double the speed of a program in under an hour. It makes so sense to ignore such low-hanging fruit.

Wise Thoughts

We should forget about small inefficiencies, say about 97% of the time: premature optimization is the root of all evil.
~ Donald Ervin Knuth (born: 1938-01-10 age: 76)
A fast program is not as important as a correct one.
~ Steve McConnell
The only result of optimization you can usually be sure of without measuring performance is that you’ve made your code harder to read.
~ Steve McConnell
Jackson’s rules of Optimization:
  1. Don’t do it.
  2. (For experts only) Don’t do it yet — that is until you have a perfectly clear and unoptimized solution.
~ M.A. Jackson

Optimisation has become a dirty word. I have even been chastised for thinking about which of two equally easy, and easy-to-maintain ways of doing something is more efficient. The problem is premature optimisation, not optimisation itself. The problem is about trading off ease of maintenance with speed. When the fast code is also the simplest and easiest to maintain, you are an idiot to avoid it, at any stage.

~ Roedy Green (born: 1948-02-04 age: 66)

How to Proceed

If you have a program that is running too slowly, here is what to do. I suggest following the steps in this order:
  1. Get someone experienced in these matters to look over your code and find out where it is spending all its time. It helps to have a fresh pair of eyes on the problem. They will use a profiler to determine this. This identifies the bottlenecks.
  2. Look at the bottleneck code for obvious blunders and correct them.
  3. See if there is a totally different faster algorithm for accomplishing the same thing, e.g. HashMap vs linear searching a long table.
  4. Clean up the bottleneck code to ship shape. This is not considered optimising, just getting it squeaky clean with no rambling.
  5. See if the program is recomputing anything. Perhaps it can avoid redoing work it has already done. The form of optimisation tends to make the code more complex and less maintainable, but not always. Sometimes inexperienced programmers call methods where they are not needed at all, and that code can be yanked out entirely.
  6. Consider the use of a native optimising compiler such as JET.
  7. If all else fails try JNI with C/ C++. Beware. JNI (Java Native Interface) only saves you CPU (Central Processing Unit) time if you can do a substantial amount of work in C/C++ on each call to offset the high overhead of the call.
  8. If even that fails try JNI with assembler.
  9. If that fails, tell your customers they will need bigger iron.

What Not To Do

General Tips

The sorts of thing you can legitimately do are:

A Touch of Cynicism

In the end, what counts in the marketplace is the psychological impression a program gives to its users.

You can speed up a program by wasting even more cycles with progress bars and animated spinners — the approach pioneered by Microsoft.

If the program behaves what appears to behave like a reluctant or lazy human, it will be perceived as slow. If a program appears industrious, it can actually be a pig and get away with it.

In GUI s, what most often counts most is some sort of rapid acknowledgement feedback not the total elapsed time of some process.

Garbage Collection

It is quite common to discover the problem is frequent and lengthy garbage collections. Understanding the problem requires a book just in itself. However, here are a few rules of thumb:

Compiler and Run Time Optimisation

Modern compilers and run times to some pretty spectacular optimisation without you having to do any work. For example, code that is not marked final will be inlined. Only later if some overriding class is loaded will the inlining be dynamically undone. Jet does loop versioning. If you had a loop that for example kept checking if it were an odd or even iteration, Jet would split the code into two versions, one for odd and one for even, and do the test only once at the top.

Optimisations I would like to see:

Books

book cover recommend book⇒Java Performance: The Definitive Guideto book home
by Scott Oaks 978-1-4493-5845-7 paperback
publisher O’Reilly recommended 978-1-4493-6353-6 eBook
published 2014-05-01 B00JLTOZVQ kindle
The cover image is not a pair of rabbits as I first thought. It covers the Java Performance Toolbox, Working with the JIT Compiler, Garbage Collection, Heap Memory Best Practices, Native Memory Best Practices, Threading and Synchronization Performance, Java Enterprise Edition Performance, Database Performance Best Practices, Java SE API Tips, and tuning flags.
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java Performanceto book home
by Charlie Hunt, Binu John 978-0-13-714252-1 paperback
publisher Addison-Wesley Professional 978-0-13-290524-4 eBook
published 2011-10-14 B005R4NELQ kindle
Charlie Hunt is the JVM performance lead engineer at Oracle. He is responsible for improving the performance of the HotSpot JVM and Java SE class libraries. He has also been involved in improving the performance of the Oracle GlassFish and Oracle WebLogic Server. This also covers the JVM’s internal architecture (including its memory model and garbage collectors) and the art of benchmarking and performance testing.
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
book cover recommend book⇒Code Complete: A Practical Handbook of Software Constructionto book home
by Steve McConnell 978-1-55615-484-3 paperback
publisher Microsoft 978-0-7356-3697-2 eBook
published 1993-05-14
Gives lots of practical advice on optimising. He talks mostly about C with examples in Fortran, Pascal, Basic and Ada. He doesn’t talk about Java. It didn’t exist when the book was written.
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java Performance Tuning, second editionto book home
by Jack Shirazi 978-0-596-00377-7 paperback
publisher O’Reilly recommended
published 2003-01-21
Recommended. O’Reilly Safari book available to read online for a fee. Includes tuning EE, JDBC, servlets and JSPs, and EJBs. Make sure you get the second edition (or later).
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java Platform Performance: Strategies and Tacticsto book home
by Steve Wilson, Jeff Kesselman 978-0-201-70969-8 paperback
publisher Prentice Hall
published 2000-06-10
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Enterprise Java Performanceto book home
by Steven L. Halter, Steven J. Munroe 978-0-13-017296-9 paperback
publisher Prentice Hall
published 2000-08
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Sun Performance and Tuning: Java and the Internet, second editionto book home
by Adrian Cockcroft, Richard Pettit, Sun Microsystems 978-0-13-095249-3 paperback
publisher Prentice Hall
published 1998-04-17
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Java ™ Puzzlers: Traps, Pitfalls, and Corner Casesto book home
by Joshua J. Bloch, Neal Gafter 978-0-321-33678-1 paperback
birth 1961-08-28 age: 53 978-0-321-64351-3 eBook
publisher Addison-Wesley B001U5VJVS kindle
published 2005-07-04
A set of 95 short programs that give astonishing results. When you understand them, you understand the quirkier features of Java. Bloch wrote much of the JDK class library. He also wrote the Effective Java Programming Language Guide
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Effective Java: second editionto book home
by Joshua J. Bloch 978-0-321-35668-0 paperback
birth 1961-08-28 age: 53 978-0-13-277804-6 eBook
publisher Prentice Hall 978-0-13-715002-1 WebBook
published 2008-05-28 B000WJOUPA kindle
No design patterns, just generic advice on good Java programming style. This is considered the best explanation of generics, even though it has just one chapter on generics. People claim it all came clear after reading his explanation. It is also consider the best explanation of serialization. Not to be confused with his earlier Effective Java Programming Language Guide. book website
Australian flag abe books anz abe books.co.uk UK flag
Chinese flag amazon.cn amazon.co.uk UK flag
German flag abe books.de abe books.ca Canadian flag
German flag amazon.de amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Google play American flag
Italian flag amazon.it O’Reilly Safari American flag
India flag junglee.com Powells American flag
UN flag Kobo other stores UN flag

This page is posted
on the web at:

http://mindprod.com/jgloss/optimising.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\optimising.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Blog
IP:[65.110.21.43]
Your face IP:[54.81.134.175]
You are visitor number