JAVA technology performance myths exposed.

Tags:

JAVA technology performance myths exposed

Interstingly enough, foreach loops are not slower than for loops. I can’t believe it, because I myself saw large performance degrade when I used the iterator pattern instead of loop counter based iteration.

Here’s my one penny regarding iteration issues. Suppose that you have some class, and that you want to manipulate the way how elements are iterated. Such a situation can arise when some parts of elements should be hidden from some kinds of classes. That being the case, states for iteration must be maintained and that obviously requries CPU costs. Moreover, iterators in JAVA can not return primitive types, while C++ can. That means, whenever you want to retrieve some primitive elements, it must be wrapped into an object, and that also must be unwrapped when iterator.next() method call returns, because the caller of the method may be expecting a primitive type. Again, this can be expensive. Anyway, the presentation given by the author disavows such a possibility.

Things that worth rembering is that values() method of Enum classes are way too slows. The reason is that Enum classes do defensive copying for hiding its internal state. Plus, hacks for avoiding virtual method calls, though they are proven to be useless, are quite interesting. I can’t figure out how they devised such a novel way.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *