Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optimizing in Java

Status
Not open for further replies.

daniel135

Programmer
Apr 9, 2002
93
CA
this thread is an offshoot of another (thread269-269889 Java, is it better than c++ or c# ?)

in it, myenigmaself wrote:
"a lot of the problems (of speed) occur when people don't know how to harness the power of Java. An example is that people never encapsulate Strings in StringBuffers. This greatly improves performance because it decreases the number of times you have to allocate memory... it's the little things like this that only come with experience that make a program run efficiently."

Ok, so I knew about StringBuffers... but what else am I missing? Does anyone else know of common mistakes people make that slow things down? If so, please post!
 
do a search for Duff's device online as well as the term "unrolling". it's quite impressive what you can do with that.

Often you can speed things up a lot just by designing your algos a bit better but places where you will see easy improvements is usually loops. Gary Haran
 
I'm an extreme newbie to Java, but one thing I have learned is that declaring an int (or any other data type) as public or protected takes more time within the JVM then if it's declared as final (given, of course that the variable is static throughout the program). Although this "time" is too quick to notice, it does add up in larger programs.

-a5k
 
Declaring methods as final also reduces some overhead. If you subclass, though, you lose the ability to overload those methods.

Optimizing tools like "Optimizer" can point you towards inefficient object usage. Since object creation causes a big speed hit, a general rule is to reuse objects whenever possible, especially in loops.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top