Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

JVM Languages

Optimized Java


Matt is a software development manager with Parasoft. He can be contacted at [email protected].


The performance dynamics of Java programs are related to fundamental designs in the language itself. Java source code compiles to an intermediate language that a virtual machine (VM) can run on any platform for which the VM has been implemented. Microsoft's .NET is a similar intermediate language and VM design. Most engineers believe that programming languages that offer more abstraction from the hardware and operating system suffer from slower performance. Interpreted languages executed directly from source code without compilation (Perl, for example) are generally used only for scripting because full-blown applications run faster without the overhead of interpreting source code every time.

At the other end of the spectrum, compiled languages such as C++ are typically used when performance is a priority because they produce executables optimized for specific hardware and operating systems. Portability and maintainability are also deciding factors in selecting a programming language. Compiled languages require a dedicated build process for each supported platform, while intermediate languages and interpreted languages execute similarly on multiple platforms as-is (although interpreted languages are not used for commercial software when the original source must be kept hidden). Thus intermediate languages, such as Java and .NET, emerge as a good trade-off between performance optimizations and portability.

Memory management is a major factor affecting software application performance. Typically, more time is spent allocating/deallocating memory than performing actual data computation. While C++ offers direct control over when memory is allocated and freed, Java attempts to abstract memory management by using garbage collection to reclaim memory that the program no longer needs. However, the "pause" associated with garbage collection has been the central argument against using Java when real-time performance is required. Typically, garbage collection is a periodic process that pauses normal program execution to analyze object references and reclaim memory that was allocated but can no longer be accessed by reference. In large Java applications, the pause for garbage collection can last several seconds, which is enough to disrupt any type of real-time communication or control system. Consequently, the memory abstraction provided by garbage collection requires performance-oriented developers to think more carefully about memory management. Even though Java does not provide the same level of control over memory deallocations as C++, programming patterns can still make a huge difference in the memory performance of Java applications.

Overall, the performance improvements that Sun has made to Java over the past decade, combined with proper coding patterns, lets Java compete with other interpreted and compiled languages for the performance crown. Changes to the language grammar in Java 5.0 increase ease of development by including celebrated elements of other languages. However, some language changes contain hidden pitfalls and sacrifice performance in favor of ease-of-use. In this article, I explore the performance implications of implementing some common algorithms using old and new language features to help you decide which patterns should be encouraged or avoided, relative to performance.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.