Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Java Performance Tuning, 2nd Ed.

Posted by timothy on Wed Apr 09, 2003 11:00 AM
from the percolation dept.
cpfeifer writes "Performance has been the albatross around Java's neck for a long time. It's a popular subject when developers get together "Don't use Vector, use ArrayList, it's more efficient." "Don't concatenate Strings, use a StringBuffer, it's more efficient." It's a chance for the experienced developers to sit around the design campfire and tell ghost stories of previous projects where they implemented their own basic data structures {String, Linked List...} that was anywhere from 10-50% faster than the JDK implementation (and in the grand oral tradition of tall tales, it gets a little more efficient every time they tell it)." Want to kill the albatross? Read on for the rest of cpfeifer's review of O'Reilly's Java Performance Tuning, now in its 2nd edition.
Java Performance Tuning, 2nd Edition
author Jack Shirazi
pages 570
publisher O'Reilly and Associates
rating 9/10
reviewer cpfeifer
ISBN 096003773
summary It's the most up to date publication dealing specifically with performance of Java applications, and is a one of a kind resource.

Every developer has written a microbenchmark (a bit of code that does something 100-1000 times in a tight loop and measure the time it takes for the supposed "expensive operation") to try and prove an argument about which way is "more efficient" based on the execution time. The problem, is when running in a dynamic, managed environment like the 1.4.x JVM, there are more factors that you don't control than ones that you do, and it can be difficult to say whether one piece of code will be "more efficient" than another without testing with actual usage patterns. The second edition of Review of Java Performance Tuning provides substantial benchmarks (not just simple microbenchmarks) with thorough coverage of the JDK including loops, exceptions, strings, threading, and even underlying JVM improvements in the 1.4 VM. This book is one of a kind in its scope and completeness.

The Gory Details


The best part of this book is that it not only tells you how fast various standard Java operations are (sorting strings, dealing with exceptions, etc.), but he has kept all of the timing information from the previous edition of the book. This shows you how the VMs performance has changed from version 1.1.8 up to 1.4.0, and it's very clear that things are getting better. The author also breaks out the timing information for 3 different flavors of the 1.4.0 JVM: mixed interpreted/compiled mode (standard), server (with Hotspot), and interpreted mode only (no run time optimization applied).

Part 1 : Lies, Damn Lies and Statistics
The book starts off with three chapters of sage advice about the tools and process of profiling/tuning. Before you spend any time profiling, you have to have a process and a goal. Without setting goals, the tuning process will never end and it will likely never be successful.

The author outlines a general strategy that will give you a great starting point for your tuning task forces. Chapter 2 presents the profiling facilities that are available in the Java VM and how to interpret the results, while chapter 3 covers VM optimizations (different garbage collectors, memory allocation options) and compiler optimizations.

Part 2 : The Basics
Chapters 4-9 cover the nuts and bolts, code-level optimizations that you can implement. Chapter 4 discusses various object allocation tweaks including: lazy initialization, canonicalizing objects, and how to use the different types of references (Phantom, Soft, and Weak) to implement priority object pooling. Chapter 5 tells you more about handling Strings in Java that you ever wanted to know. Converting numbers (floats, decimals, etc) to Strings efficiently, string matching -- it's all here in gory detail with timings and sample code.

This chapter also shows the author's depth and maturity; when presenting his algorithm to convert integers to Strings, he notes that while his implementation previously beat the pants off of Sun's implementation, in 1.3.1/1.4.0 Sun implemented a change that now beats his code. He analyzes the new implementation, discusses why it's faster without losing face. That is just one of many gems in this updated edition of the book. Chapter 6 covers the cost of throwing and catching exceptions, passing parameters to methods and accessing variables of different scopes (instance vs. local) and different types (scalar vs. array). Chapter 7 covers loop optimization with a java bent. The author offers proof that an exception terminated loop, while bad programming style, can offer better performance than more accepted practices.

Chapter 8 covers IO, focusing in on using the proper flavor of java.io class (stream vs. reader, buffered vs. unbuffered) to achieve the best performance for a given situation. The author also covers performance issues with object serialization (used under the hood in most Java distributed computing mechanisms) in detail and wraps up the chapter with a 12 page discussion of how best to use the "new IO" package (java.nio) that was introduced with Java 1.4. Sadly, the author doesn't offer a detailed timing comparison of the 1.4 NIO API to the existing IO API. Chapter 9 covers Java's native sorting implementations and how to extend their framework for your specific application.

PART 3 : Threads, Distributed Computing and Other Topics
Chapters 10-14 covers a grab bag of topics, including threading, proper Collections use, distributed computing paradigms, and an optimization primer that covers full life cycle approaches to optimization. Chapter 10 does a great job of presenting threading, common threading pitfalls (deadlocks, race conditions), and how to solve them for optimal performance (e.g. proper scope of locks, etc).

Chapter 11 provides a wonderful discussion about one of the most powerful parts of the JDK, the Collections API. It includes detailed timings of using ArrayList vs. LinkedList when traversing and building collections. To close the chapter, the author discusses different object caching implementations and their individual performance results.

Chapter 12 gives some general optimization principles (with code samples) for speeding up distributed computing including techniques to minimize the amount of data transferred along with some more practical advice for designing web services and using JDBC.

Chapter 13 deals specifically with designing/architecting applications for performance. It discusses how performance should be addressed in each phase of the development cycle (analysis, design, development, deployment), and offers tips a checklist for your performance initiatives. The puzzling thing about this chapter is why it is presented at the end of the book instead of towards the front, with all of the other process-related material. It makes much more sense to put this material together up front.

Chapter 14 covers various hardware and network aspects that can impact application performance including: network topology, DNS lookups, and machine specs (CPU speed, RAM, disk).

PART 4 : J2EE Performance
Chapters 15-18 deal with performance specifically with the J2EE APIs: EJBs, JDBC, Servlets and JSPs. These chapters are essentially tips or suggested patterns (use coarse-grained EJBs, apply the Value Object pattern, etc) instead of very low-level performance tips and metrics provided in earlier chapters. You could say that the author is getting lazy, but the truth is that due to huge number of combinations of appserver/database vendor combinations, it would be very difficult to establish a meaningful performance baseline without a large testbed.

Chapter 15 is a reiteration of Chapter 1, Tuning Strategy, re-tooled with a J2EE focus. The author reiterates that a good testing strategy determines what to measure, how to measure it, and what the expectations are. From here, the author presents possible solutions including load balancing. This chapter also contains about 1.5 pages about tuning JMS, which seems to have been added to be J2EE 1.3 acronym compliant.

Chapter 16 provides excellent information about JDBC performance strategies. The author presents a proxy implementation to capture accurate profiling data and minimize changes to your code once the profiling effort is over. The author also covers data caching, batch processing and how the different transaction levels can affect JDBC performance.

Chapter 17 covers JSPs and servlets, with very little earth shattering information. The author presents tips such as consider GZipping the content before returning it to the client, and minimize custom tags. This chapter is easily the weakest section of the book: Admittedly, it's difficult to optimize JSPs since much of the actual running code is produced by the interpreter/compiler, but this chapter either needs to be beefed up or dropped from future editions.

Finally, chapter 18 provides a design/architecture-time approach towards EJB performance. The author presents standard EJB patterns that lend themselves towards squeezing greater performance out of the often maligned EJB. The patterns include: data access object, page iterator, service locator, message facade, and others. Again, there's nothing earth shattering in this chapter. Chapter 19 is list of resources with links to articles, books and profiling/optimizing projects and products.

What's Bad?

Since the book has been published, the 1.4.1 VM has been released with the much anticipated concurrent garbage collector. The author mentions that he received an early version of 1.4.1 from Sun to test with. However, the text doesn't state that he used the concurrent garbage collector, so the performance of this new feature isn't indicated by this text.

The J2EE performance chapters aren't as strong as the J2SE chapters. After seeing the statistics and extensive code samples of the J2SE sections, I expected a similar treatment for J2EE. Many of the J2SE performance practices still apply for J2EE (serialization most notably, since that his how EJB, JMS, and RMI ship method parameters/results across the wire), but it would be useful to fortify these chapters with actual performance metrics.

So What's In It For Me?

This book is indispensable for the architect drafting the performance requirements/testing process, and contains sage advice for the programmer as well. It's the most up to date publication dealing specifically with performance of Java applications, and is a one-of-a-kind resource.


You can purchase Java Performance Tuning, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • Web pages (Score:1, Insightful)

    by Mattygfunk1 (596840) on Wednesday April 09 2003, @11:10AM (#5693606)
    (http://www.servergrade.com.au/)
    For applications and easy of development Java is sensational, but for everybodys sake PLEASE DON'T USE JAVA ON WEB PAGES WHEN IT ISN'T NECESSARY. As you might pick up on - I hate it, and most of your users do too.

    Networking and secure transactions asside, I have a major problem with things like scrolling text java applets. The problem is I see it too much.

    /pet-hate rant. grrrrr.

    __
    cheap web site hosting [cheap-web-...ing.com.au] with coins per month.

    • Insightful? (Score:4, Insightful)

      by rfischer (95276) on Wednesday April 09 2003, @11:40AM (#5693735)
      Remember there is a distinction between client- and server-side Java. Java on the server makes me very happy.
      [ Parent ]
      • Re:Insightful? by rfischer (Score:1) Wednesday April 09 2003, @11:58AM
      • 1 reply beneath your current threshold.
    • Re:Web pages (Score:4, Interesting)

      by catch23 (97972) on Wednesday April 09 2003, @11:44AM (#5693750)
      Why would the users care whether you use a J2EE or PHP4 backend? You must be thinking of Java applets which very few few people actually use for any "web page development". And the chapters 15-18 that talk about J2EE, what's wrong with using J2EE for the generation of webpages and content?
      [ Parent ]
      • Re:Web pages by juhaz (Score:1) Wednesday April 09 2003, @12:10PM
      • Re:Web pages by Malc (Score:1) Wednesday April 09 2003, @03:30PM
      • Re:Web pages by KinkyClown (Score:1) Thursday April 10 2003, @01:01AM
      • 1 reply beneath your current threshold.
    • Insightful!? by Jerk City Troll (Score:2) Wednesday April 09 2003, @12:52PM
    • Re:Web pages by Kombat (Score:1) Wednesday April 09 2003, @01:01PM
      • 1 reply beneath your current threshold.
    • Re:Web pages by msuzio (Score:2) Wednesday April 09 2003, @01:19PM
    • Re:Web pages by angel'o'sphere (Score:2) Wednesday April 09 2003, @07:14PM
    • 1 reply beneath your current threshold.
  • Isn't this the compiler's job? (Score:5, Insightful)

    by chrisseaton (573490) on Wednesday April 09 2003, @11:11AM (#5693611)
    (http://www.chrisseaton.com/blog/)
    If all these performance hacks are documented, why doesn't the compiler implement them?

    I've often found that will bytecode languages (Java, C#...) the bytecode instructions are made for the language so that the compiler can just throw them out easy peasy, but they seem to overlook the sort of optimizations that C compilers, for example, work hard to implement.
    • Re:Isn't this the compiler's job? by p3d0 (Score:2) Wednesday April 09 2003, @11:27AM
    • Re:Isn't this the compiler's job? (Score:5, Informative)

      by cmburns69 (169686) on Wednesday April 09 2003, @11:39AM (#5693726)
      (http://www.netnexus.com/access/ | Last Journal: Thursday October 21 2004, @11:47AM)
      With non-bytecode langauges, the compiler can optimize to the environment. It can re-order code based on the fastest execution time for the platform the code is compiled for.

      Java (and other bytecode languages) were desinged to run well not just on a single platform, but on a variety of platforms. So as a trade-off, you lose environment-specific optimizations at compile time.

      JIT JRE/compilers can work to prevent this. They can further optimize the bytecodes at execution time because they are platform specific.

      An online Starcraft RPG? Only at [netnexus.com]
      In soviet Russia, all your us are belong to base!
      [ Parent ]
    • Re:Isn't this the compiler's job? (Score:5, Insightful)

      by briaydemir (207637) on Wednesday April 09 2003, @12:41PM (#5693982)

      If all these performance hacks are documented, why doesn't the compiler implement them?

      The most common reason is that most performance hacks and optimizations are not decidable, and you want a compiler to implement only decidable algorithms becuase those are the ones that enable a compiler to be deterministic. It is usually much easier for a person, i.e., human, to determine what can be done, than it is for a machine to determine that exact same thing.

      Consider the following piece of code.

      boolean f(int[] a, int[] b)
      {
      int x = a[0];
      b[0] = a[0] + 2;
      int y = a[0];
      return (x == y);
      }

      Does f always return true? Only if we can prove that a and b never point to the same array. A person maybe able to do this, but a machine would have great difficulty (assuming the machine could even do it).

      So to sumarize, compiler's don't implement many optimization hacks becuase then they might not be deterministic, and that is a bad thing.

      [ Parent ]
    • interpreted is bad enough by xpl_the_myst (Score:1) Thursday April 10 2003, @12:11AM
    • Re:Isn't this the compiler's job? (Score:4, Informative)

      by chrisseaton (573490) on Wednesday April 09 2003, @11:35AM (#5693717)
      (http://www.chrisseaton.com/blog/)
      Think about the string object problem - people have to use stringbuffer because strings are immutable.

      When a program thrashes strings around, why doesn't the compiler detect that, and switch to a string buffer object to perform those operations, and then convert the final result back to a string?
      [ Parent ]
      • Re:Isn't this the compiler's job? by jd10131 (Score:2) Wednesday April 09 2003, @12:01PM
      • Re:Isn't this the compiler's job? by dubious9 (Score:2) Wednesday April 09 2003, @12:04PM
      • String/StringBuffer (Score:5, Informative)

        by toriver (11308) on Wednesday April 09 2003, @12:10PM (#5693860)
        It does under the hood whenever you use + for concatenation; this is why using String + String in a loop is ineffective: You create a new StringBuffer object per iteration. The solution in this case is to declare the StringBuffer outside the loop and use append() explicitly within.

        For concatenating two strings, the concat() method can be faster than using StringBuffer, since it only needs to create a new char[] and do a (fast) arraycopy from the two internal arrays.

        Also, everyone should be aware of the 1.4.1 memory leak associated with using StringBuffer's toString() and setLength() methods.
        [ Parent ]
      • For most of theses transformations to be correct, the compiler has to prove there is only one pointer to the object -- in the whole program. Whole-program analyses are expensive, and so are point-to [nec.com]analysis. And there is just not that kind of time to spare in a JIT, where every second spent analysing the program is time spent not executing it.

        The optimization the book proposes are all hit-or-miss adventures. Even for a programmer with intimate knowledge of the code, it is sometime difficult to predict if a change will help or imper performance. The compiler has even less chance to do so correctly -- and nobody like a compiler which slows down their code trying to optimize it.

        [ Parent ]
        • 1 reply beneath your current threshold.
      • Re:Isn't this the compiler's job? by abiogenesis (Score:1) Wednesday April 09 2003, @04:04PM
    • 3 replies beneath your current threshold.
  • Definite purchase (Score:3, Informative)

    by Timesprout (579035) on Wednesday April 09 2003, @11:13AM (#5693622)
    I have drastically cut back on my tech book purchases in recent times but this book will definitely be on my shopping list. The First edition offered many insights into not only getting the best performance from Java but also solid guidelines for when and where to apply optimisations.
    As a side note I would disagree about performance being an albatross for Java. Well written Java code can be very high performant just as poorly written code in ANY language can perform slowly. Many of the performance issues associated with Java are inexperienced developers using inappropriate methods and objects.
    • 1 reply beneath your current threshold.
  • New Title (Score:3, Funny)

    by borg05 (161991) on Wednesday April 09 2003, @11:20AM (#5693655)
    (http://www.dennistighe.com/)
    Java Performance Tuning: A course in C programing
    • Re:New Title by Anonymous Coward (Score:1) Wednesday April 09 2003, @12:40PM
      • Re:New Title by Anonymous Coward (Score:2) Wednesday April 09 2003, @01:01PM
        • 1 reply beneath your current threshold.
      • Re:New Title by borg05 (Score:1) Friday April 11 2003, @02:37AM
    • 1 reply beneath your current threshold.
  • Is this a review or a synopsis? (Score:3, Insightful)

    by rfischer (95276) on Wednesday April 09 2003, @11:21AM (#5693660)
    there is a difference, you know.
    • 1 reply beneath your current threshold.
  • Correct ISBN is 0596003773 (Score:5, Informative)

    by zipwow (1695) <(zipwow) (at) (gmail.com)> on Wednesday April 09 2003, @11:24AM (#5693669)
    (http://zipwow.net/ | Last Journal: Thursday September 12 2002, @12:54PM)
    The bn.com link is broken for me, here's the correct ISBN:

    0596003773

  • Java Strings are the main problem (Score:3, Interesting)

    by Anonymous Coward on Wednesday April 09 2003, @11:28AM (#5693693)
    Each String is around 64 bytes of memory minimum. What a stupid decision to make such a fundamental data type so heavy weight.
  • I have noticed my JAVA programs run considerably faster under the Sun Forte/One IDE. Once the JAVA app is on its own (especially through a browser), it slows considerably. Does anyone else have experience with this phenomenon?
  • Process (Score:3, Insightful)

    by spakka (606417) on Wednesday April 09 2003, @11:28AM (#5693697)

    The book starts off with three chapters of sage advice about the tools and process of profiling/tuning. Before you spend any time profiling, you have to have a process and a goal. Without setting goals, the tuning process will never end and it will likely never be successful.

    No, you have to profile first. Profiling will tell you whether there is even any point in tuning, and, if so, what goals are reasonable.

    • Re:Process by egoots (Score:2) Wednesday April 09 2003, @01:30PM
    • Re:Process by adz (Score:1) Wednesday April 09 2003, @02:44PM
    • 1 reply beneath your current threshold.
  • What performance issues? (Score:5, Funny)

    by Anonymous Coward on Wednesday April 09 2003, @11:29AM (#5693705)
    Java has performance troubles? I thought we were all supposed to deny that. Did I miss a memo or something?
  • by OwnStile (261614) on Wednesday April 09 2003, @11:37AM (#5693725)
    Anyone wanting to know about JAVA performance tuning should be sure to look at the time honored review of Why JAVA Sucks for Sysadmins [panix.com] .

    Keith
    • by markv242 (622209) on Wednesday April 09 2003, @12:59PM (#5694140)
      I forwarded this article to our sysadmins, and they basically laughed it off. At least for web-based applications, almost none of these points apply. The article talks about the author's hatred of JVM startup times (which don't apply for an application server) and exception verbosity (which any real java developer will catch and deal with himself, rather than leaving it up to the sysadmin(?) to deal with).

      I challenge you to make a C++/C# application that is thread-safe and can scale to millions of pageviews per day without writing a ton of supporting code. With a good J2EE app server, a java coder essentially just has to wrap his thread-unsafe code in a syncronized() statement, and he's done-- his app is now thread-safe.

      Additionally, the "cross-platform doesn't matter for sysadmins" is a false statement; our CIO asked our net ops group "what would be the impact of us moving to an Intel platform?" and our sysadmins (after consulting with the coders) replied "absolutely no impact". That made our CIO very, very happy. Again, I challenge you to move your C++ apps from Solaris to Linux, or even to Windows, without any hiccup.

      All of these other arguments are very specious: "I don't have enough RAM" will get you a reply of "go down to Fry's and spend $125 on another GB" every time. Processor speeds, even on Sun boxes, is getting to the point where the processor will never be a bottleneck for anything. Sure, java won't run as fast as a natively-compiled app. Neither will perl, php, tcl, or what have you. Raw processor speed is not as important when you have a couple of GHz to play with.

      [ Parent ]
    • Re:Pre-written appendix for Java Tuning by josevnz (Score:1) Wednesday April 09 2003, @01:33PM
    • by egomaniac (105476) on Wednesday April 09 2003, @01:36PM (#5694446)
      (http://slashdot.org/)
      That article is the most absurd joke I have ever read. He spends half the article complaining about Java's startup time (which (A) does not apply in any server situation, and (B) is unfair, because you don't count the machine's bootup time when talking about the performance of C programs, do you?).

      Then he invents other ways to talk about the startup time without seeming to talk about the startup time (for instance, trussing Hello World results in a ton of output, but naturally that's Java starting up and loading its classes. Again, do you consider what the machine has to do to boot itself up when you're talking about C programs?). I will point out again that Java's startup time is almost irrelevant, especially in a server environment (which is what he's talking about).

      The rest of the article is picking on the "jar" tool. jar is a program written in Java. Criticisms against the jar tool no more reflect on Java than criticisms against gzip reflect on C. The fact that jar doesn't do a good job of reporting errors is (A) irrelevant, because it's a developer tool and we know how to read exceptions, and (B) still more irrelevant, because how well it reports errors has nothing to do with what language it was written in. Tons of C programs have lousy error reporting as well, such as a number of Unix utilities I might name.

      Further, this article is obviously very old. He's talking about Java 1.1.8, which is what, five years old now? Might as well criticize Linux by talking about obscure video driver bugs that were fixed five years ago. Obviously, that's not the article's fault for having been written so long ago, but it is the parent poster's fault for bringing it up as if it is somehow still relevant.
      [ Parent ]
    • Re:Pre-written appendix for Java Tuning by hibiki_r (Score:1) Wednesday April 09 2003, @03:32PM
    • 1 reply beneath your current threshold.
  • This is awesome! I am just getting back into a Java project again and wasn't aware that this book existed.

    The only frustration is that I use safari.oreilly.com and love it, but they don't seem to have the 2nd edition from what I can tell... oh well - I'll add the edition that comes up in the search and that's better than nothing.
  • Java doesn't cut it (Score:3, Interesting)

    by AirLace (86148) on Wednesday April 09 2003, @11:43AM (#5693745)
    We ported some of our internal Java business applications to C# for use with Mono, and emperical results already suggest the solution is several times faster than the Java code. The port was very easy, with each line of Java code mapping onto one line of C# or less. Porting the UI to Gtk# was more difficult, but we find the Gtk# code more maintainable and the UI, along with the Gtk+ WIMP [sourceforge.net] plugin integrates much more nicely with Windows than SWING. We'll be investigating a switch to Linux over the next few months for some of our Point-of-Sales terminals as a result, and it should be easy thanks to the portability of Mono and Gtk#.

    We also ported some of our backend tools for use with Mono. In use with the newly released Mono JIT runtime, Mini [ximian.com], we've achieved some truly stunning results. It turns out that some of the optimisations in the new JIT are better than those used by GCC, so once the code is loaded in memory, it performs better than raw C code. Although I don't yet have hard numbers to back up these result (the transition is still in progress), it has to be said that Mono is the real answer to Java performance. Being Open Source, we can also contribute back to the runtime to make it better suit our needs. It also plays nicely with RedHat 9's NPTL threading implementation, which is more than I can say for the current crop of Java JREs.
    • Re:Java doesn't cut it by sbrown123 (Score:3) Wednesday April 09 2003, @12:16PM
      • Re:Java doesn't cut it (Score:5, Insightful)

        by AirLace (86148) on Wednesday April 09 2003, @12:33PM (#5693951)
        You could have saved yourself some porting by just compiling your java code with GCJ. GCJ allows you to compile your java byte code to native executables.

        This might become an option in a few years, but the GNU classpath is as yet not complete enough for our years. We actually didn't find gcj output that performant, despite it being compiled to native code. The JRE still beat it in many cases.

        Use SWT with Java. SWT uses Windows native widgets on Windows or GTK on Linux.

        We also investigated this. SWT is a _horrendous_ API which offers very little abstraction. You end up writing your code once for the Gtk+ target, and again for the native Windows target. It isn't really a cross-platform abstraction like WxWindows, and it's probably the reason why the Eclipse codebase is so large. You end up writing your application for each UI target platform. Gtk# runs and integrates with the platform instead, so you only write your code once.

        Either your telling a big lie or dont have your facts straight. Unless you can show hard facts your not going to sway anyone into believing interpreted code outperformed compiled.

        I did mention the results are empirical, but they're also pretty obvious from where I stand. You don't need benchmarks when something performs, in some cases, eight times faster than the original implementation. I may well put togther some benchmarks and post them to mono-list or linuxtoday.com. I don't have benchmarks yet; does that make me a liar? Sigh.

        What is exactly wrong with Java's use of native threads on Linux boxes?

        It's pointless to interface with the threads layer directly when pthreads exists. It makes the runtime essentially unportable to other unices/operating systems. Mono plays nicely with the environment, so the runtime can just be compiled on any POSIX-compilant system. Linux is great, but being attached to it so firmly that your application breaks when Linus changes some internal interfaces is not.
        [ Parent ]
      • just-in-time compilation by Submarine (Score:2) Wednesday April 09 2003, @03:27PM
      • 1 reply beneath your current threshold.
    • Re:Java doesn't cut it by Headius (Score:2) Wednesday April 09 2003, @02:51PM
    • Re:Java doesn't cut it by wirde (Score:1) Wednesday April 09 2003, @03:01PM
    • Re:Java doesn't cut it by Anonymous Coward (Score:1) Wednesday April 09 2003, @01:04PM
    • 3 replies beneath your current threshold.
  • Inherent performance issues (Score:3, Informative)

    by MSBob (307239) on Wednesday April 09 2003, @11:44AM (#5693751)
    There are certain design decisions that were made by the java team that limit java's performance in a number of ways. Lack of stack objects comes to mind and collections that cannot store basic types.

    That said for most network centric applications java is plenty fast. Now if we only stopped short of introducing the unbelievable overhead of XML's excessive verbosity...

  • idiots.; (Score:2, Interesting)

    by mandrake*rpgdx (650221) on Wednesday April 09 2003, @11:46AM (#5693755)
    (http://pauljessup.blogspot.com/)
    Why does programming languages have to be an either or situation? Everyone here assumes that anyone who programs in JAva does not know C/C++...why is that? Can't someone know multiple prog langs? I know many (too many too really list here) and find it asinine that people really think that everyone should just program in one lang.
    • Re:idiots.; (Score:5, Insightful)

      by iapetus (24050) on Wednesday April 09 2003, @12:24PM (#5693914)
      (http://www.veryshortpier.com/)
      Because the sort of people who like to get involved in discussions about whether C# is 'better' than Java or Java is 'better' than Perl or crunchy peanut butter is 'better' than textured masonry paint can't cope with more than one thing at a time, and tend to apply their religious zealotry with great vigour.

      Those of us who can program in more than one language and know that sometimes it's a matter of choosing the right tool for the job (peanut butter for sandwiches, masonry paint for walls) tend to go through three stages:

      1) Try to engage in such discussions on the premise that there's actual intelligent debate going on.

      2) Discover ourselves becoming violently opposed to whatever rant we're reading at the time, writing tracts about how Java sucks when we're reading the work of a Java fanatic and drooling about the glory of Java when faced with a C++-toting moron.

      3) Either give up in disgust and let the language fanboys get on with it, or sit on the sidelines and snipe at both sides - similar to stage 2, but more consciously applied. Normally that progresses towards giving up, though, since the zealots are just too easy and predictable...
      [ Parent ]
    • really. by mandrake*rpgdx (Score:1) Wednesday April 09 2003, @03:34PM
      • 1 reply beneath your current threshold.
    • and by efficient you mean? *n/t by mandrake*rpgdx (Score:1) Wednesday April 09 2003, @03:37PM
    • 2 replies beneath your current threshold.
  • Finally (Score:1)

    by loserdave (233584) on Wednesday April 09 2003, @11:47AM (#5693758)
    (http://www.cnn.com)
    ...another Slashdot book report.

  • More efficient != better (Score:3, Insightful)

    by brianjcain (622084) on Wednesday April 09 2003, @11:50AM (#5693764)
    (Last Journal: Wednesday December 17 2003, @09:23AM)
    "Don't concatenate Strings, use a StringBuffer, it's more efficient."

    Perhaps it is more efficient. I say, let the compiler do it for me. Code like this:
    final String foo = frob + " noz " + baz.barCount()
    + " bars found";
    is much more readable/maintainable than
    StringBuffer fooBuff = new StringBuffer();
    fooBuff.append(frob);
    fooBuff.ap pend(" noz, ");
    fooBuff.append(baz.barCount());
    fooBuff.appe nd(" bars found");
    final String foo = fooBuff.toString();
  • by drgroove (631550) on Wednesday April 09 2003, @12:10PM (#5693864)
    "The J2EE performance chapters aren't as strong as the J2SE chapters. After seeing the statistics and extensive code samples of the J2SE sections, I expected a similar treatment for J2EE. Many of the J2SE performance practices still apply for J2EE (serialization most notably, since that his how EJB, JMS, and RMI ship method parameters/results across the wire), but it would be useful to fortify these chapters with actual performance metrics."

    J2SE has more coverage, because this is the area where Sun is focusing right now on improving speed. J2EE has been fairly successful - also, since CPU, RAM, HD resources tend to be more excessive on servers than desktops, J2EE speed on the server isn't as critical than J2SE speed on the desktop. Getting Java-based desktop apps to perform as well as their C/C++ brethern is the 'holy grail' of Java/J2SE development right now, so the focal point of this book makes perfect sense.
  • Who cares? (Score:5, Insightful)

    by Elgon (234306) on Wednesday April 09 2003, @12:10PM (#5693865)
    Okay,

    flippant comment but let's think about this for a second: The majority of the time the alleged efficiency advantage is small or, as is generally the case, a pointless optimisation. Java coders seem to have the major efficiency/speed hangup - they use it to lord it over scripting programmers but they want/lack/desire the swiftness of C. (And yes, I do program in Java.)

    To my mind, this is approching the problem from entirely the wrong direction: CPU time and CPU power are far cheaper than developer time and designer time. Therefore, rather than use some cobbled-together hack, use the standard implementations and take the performance hit.

    This will be cheaper, probably 95% as efficient and, most importantly, be 195% easier to maintain or change at a later date. Consider the big picture rather than a single aspect.

    NB - YMMV, for certain apps, it really does make sense to break all of the above ideas and principles, but if you REALLY need it to run that fast, you should be using C anyway.

    Elgon
    • Re:Who cares? by dubious9 (Score:2) Wednesday April 09 2003, @12:22PM
    • Re:Who cares? (Score:4, Insightful)

      by Jord (547813) on Wednesday April 09 2003, @12:25PM (#5693918)
      (http://www.zarrastudios.com/)
      True, going back and fine tuning to gain a 2% speed increase (example) is a waste of time. However the value I see in books like this is in training/teaching the developer to write more efficient code the first go around. If you get out of the habit of doing String + String + String and use StringBuffers instead your code is more efficient from the beginning.

      That is the value I see from books like this.

      [ Parent ]
      • Re:Who cares? (Score:4, Informative)

        by Randolpho (628485) on Wednesday April 09 2003, @12:49PM (#5694038)
        (http://www.google.com/ig | Last Journal: Wednesday April 11 2007, @09:55AM)
        Perhaps you should pick your examples better. Here's an exerpt from the StringBuffer JavaDoc:
        String buffers are used by the compiler to implement the binary string concatenation operator +. For example, the code:
        x = "a" + 4 + "c"
        is compiled to the equivalent of:
        x = new StringBuffer().append( "a" ).append( 4 ).append( "c" ).toString()
        Granted, people should get in the habit of coding optimizations automatically, but in this case it's actually more efficient to do String + String + String; it takes less time to code than typing the method calls, and is easier to read/understand.

        Which just brings me to my biggest beef about Java: no syntactic sugar. Operator overloading should be a part of Java, and bugger whatever the purists say. I want to save time typing dammit! :)
        [ Parent ]
    • Re:Who cares? by kp833 (Score:1) Wednesday April 09 2003, @01:38PM
    • Re:Who cares? by Capitalisten (Score:1) Wednesday April 09 2003, @01:42PM
    • Re:Who cares? by maraist (Score:3) Wednesday April 09 2003, @01:47PM
    • Re:Who cares? by plierhead (Score:2) Wednesday April 09 2003, @03:47PM
    • Re:Who cares? by jrumney (Score:2) Wednesday April 09 2003, @05:34PM
    • Re:Who cares? by tealwarrior (Score:1) Wednesday April 09 2003, @08:54PM
    • Re:Who cares? by snol (Score:1) Wednesday April 09 2003, @04:45PM
    • 1 reply beneath your current threshold.
  • I'm offended! (Score:1, Funny)

    by Anonymous Coward on Wednesday April 09 2003, @12:25PM (#5693920)
    It's Wednesday. Today we should have the weekly "XML sucks ass" -discussion, not the weekly Java bashing thread...
  • Free Software in Java? (Score:1, Offtopic)

    by Euphonious Coward (189818) on Wednesday April 09 2003, @12:40PM (#5693979)
    I'm trying to compile a list of successful, popular mainstream Free Software written in Java. (Sorry, no development tools, IDEs, ASCII editors, web-server add-ons, XML mungers -- I'm after stuff my brother might use.)

    I have Limewire.org and DVarchive already. I know about Moneydance, which might be popular someday. Freenet might work well enough someday to qualify. Anything else? If you got 'em, post 'em.

  • Albatrosses (Score:2, Interesting)

    by colin_zr (540279) on Wednesday April 09 2003, @12:41PM (#5693991)
    (http://rtnl.org.uk/)

    Want to kill the albatross?

    Ick.

    /. editors: please improve your literary references.

    The albatross doesn't need killing -- it's already dead. The albatross was hanging from the mariners neck because he had killed it, and by doing so had brought bad luck upon his ship.

    Quoting from memory here, because I can't be bothered to go find my copy of the poem:

    "God save thee, ancient mariner,
    from the fiends that plague thee thus.
    Why lookst thou so?" "With my crossbow
    I shot the albatross!"

    ...

    Ah well-a-day, what evil looks
    had I from old and young.
    Instead of the cross, the albatross
    about my neck was hung.

    ...

    Oh happy living things! No tongue
    their beauty might declare.
    A spring of love gushed from my heart
    and I blessed them unaware.

    That self-same moment I could pray
    and from my neck so free
    the albatross fell off and sank
    like lead into the sea.

    As I said, that's from memory, so there are probably plenty of mistakes in there, but I'm sure a little googling will turn up a proper copy of the poem.

  • isn't killing the albatross what got the ancient mariner into so much trouble?
  • It's all about the VM (Score:5, Insightful)

    by slagdogg (549983) on Wednesday April 09 2003, @12:49PM (#5694043)
    I read the first edition of this book completely. There are some good tips for extracting a few percentage points of improved performance. However, nothing has as profound an impact as simply using a better VM ... for example, many of my applications saw 25%+ speed increases simply by switching from the 1.2.x series VM to the 1.3.x series VM. Java does a pretty could job as a language of encouraging best practices, i.e. the inclusion of a standard StringBuffer. Extreme optimization at the code level will always be limited given the high abstraction of the language. However, extreme optimization at the VM level is a very real thing, and it doesn't take a whole lot of effort for the Java programmer.
  • Java is plenty fast (Score:2, Informative)

    by ChrisRijk (1818) on Wednesday April 09 2003, @12:57PM (#5694122)
    I've just been testing with a FFT benchmark I have, where I have both a Java version and a C version. Using GCC 3.2 on Linux, I've yet to be able to build a faster binary than what Sun's 1.4.2 beta JVM can do. IBM's JVMs are generally best at this type of benchmark, though Sun's been catching up fast, quite possibly passed them.

    Even with CPU specific optimisations, advanced compiler options etc, the Java version is 30-80% faster than GCC's binary. (this is on both AMD and Intel CPUs) To get anything faster, you'd have to pay for it.

    I also do server side programming, and I don't see why so many Linux users complain about Java's performance, while using/promoting Perl and PHP. If you want a high performance, responsive site, Java completely blows Perl and PHP away. I've only used JSP and servlets so far but they're all most web sites need anyway.
    • Re:Java is plenty fast (Score:5, Informative)

      by be-fan (61476) on Wednesday April 09 2003, @01:57PM (#5694654)
      The FFT benchmark is a very specific case. Once the JIT kicks in, it's not Java vs C++ anymore, it's the JVM optimizer vs the GCC one. Contrary to popular belief, the GCC optimizer is very good (check out benchmarks vs ICC at coytegulch.com). However, the FFT benchmark is a case where the additional information available to the JIT optimizer allows it to outperform native code. The whole benchmark is so small, it probably even fits in cache, and doesn't really stress any of the performance pitfalls of the language itself. Now, if you have a larger application, that doesn't consist of a single inner-loop, and meanders through a lot of varied code (ie. most real applications) then the performance story will be very different. At that point, Java's performance faults (excessive bookkeeping overhead, object allocation/deallocation, overhead from the JVM, etc) come much more into play.
      [ Parent ]
    • Re:Java is plenty fast by greenrd (Score:2) Wednesday April 09 2003, @03:23PM
    • 1 reply beneath your current threshold.
  • by xRelisH (647464) on Wednesday April 09 2003, @01:04PM (#5694192)
    First, I'm not a Java lover, however I have grown to respect the language. But, I would never ever want to be coding in it ( just preference and my feeling of lack of control ) . I'm currently a co-op for a wireless handheld device manufacturer (try to guess which one!) and I've learnt that Java, although slow has its merits. It's publicly known that we use a C/C++ based OS and optimized VM, and then on top of that we have our apps which are written in Java Micro edition. Although the apps are slower than our older c++ apps, we've found that the scalability really helps. We no longer need to have separate builds for each platform, and third/second party developers don't need to modify their software to have it run on our devices. It really simplifies things when you don't have to worry about CPU/chipset specific issues and worry about functionality, where the C/C++ guys (I'm in this group) can do all the hardcore work with the hardware. I'm curious to see what the next few reviews on this book say, as I'm sure some of the Java people here will appreciate it.
  • by lenmaster (598077) on Wednesday April 09 2003, @01:29PM (#5694381)

    I seem to remember seeing some benchmark that said that native compiled code was actually slower than the Hotspot JRE.

    Can any confirm this and/or explain how this is possible?

  • by snatchitup (466222) on Wednesday April 09 2003, @01:34PM (#5694423)
    (http://www.babe-test.com/ | Last Journal: Wednesday September 17 2003, @11:59AM)
    The bottleneck in our applications is not how fast whatever server-side language we use, and I imagine this is similar is most IT shops.

    Our bottleneck is how fast we can execute lots and lots of stored procedures in our SQL and Oracle databases.

    It really hasn't mattered if one of our coders has been terminating loops via try{}catch{}, or ending on a condition.

    The most important thing has been, "Does each line, each method, each class do what it's actually supposed to do?"

    Our bottlenecks have always been flow back and forth between different systems, including Lotus Domino, Oracle, MS SQL Server, Websphere, etc. etc.

    Java is a small player in all this... C++, C#, Fortran, Lisp would not speed this up for us.

  • Blah blah performance tuning... (Score:3, Interesting)

    by Lardmonster (302990) on Wednesday April 09 2003, @03:54PM (#5696070)
    So people write their own versions of linked lists and strings, to get up to 15% performance improvement. Well whoopie-fsck.

    How much does that extra development time cost?

    Writing ones' own java.lang.String takes time. Writing routines to convert com.donkeybollocks.String to java.lang.String and back again takes time. Supporting it takes time. And time is money. Me, I'd rather spend an extra £100 on a faster processor, or a Gb of RAM, and take a 25% performance improvement.

    Come on guys, one of the major wins of the OO methodology is code reuse. Time was when programmers would always have to write their own I/O routines - I thought those days were long-gone. Rewriting fundamental parts of the Java API is just plain silly, unless it has a bug or a serious limitation (eg, it's non-threadsafe).

  • 99% for me..... (Score:1)

    by luggy (184959) on Wednesday April 09 2003, @04:10PM (#5696269)
    Sounds like this guys really done his homework, but if timing is that critical ask if java should be your first choice.

    I primarily use java, both for work and home projects, and I have to say that I have almost no performance issues with java. I think that the way CPU speed has increased (and will probably continue to do so) that bytecode interpreted languages now have less of a performance gap againts native compiled code.
  • by ldesegur (547464) on Wednesday April 09 2003, @04:11PM (#5696301)
    I personally use Optimizeit Suite for Java development from Borland software [borland.com] as early as possible in the development cycle. This gives me an edge to keep the code fast and efficient without too many efforts. Including the profiling process in your development cycle avoid big surprises that you have to fix even if it's sometimes too late to revise your programs. Performance sometimes involves re-evaluating algorithms and that can't be done in code freeze. As it turn out, then even have a profiler for .NET [borland.com] that has just been released.
  • by Wordman (79573) on Wednesday April 09 2003, @04:51PM (#5696700)
    (http://pobox.com/~wordman)
    Semi-on topic: a while ago, I gave some thought to pooling StringBuffer objects to improve performance. Bad idea. This page [divnull.com] explains my findings.
    • 1 reply beneath your current threshold.
  • I've seen a lot of responses in this thread from people saying "bugger CPU time, just spend a few hundred dollars on more/faster CPU/RAM. Dev time is expensive!"

    Well, yes it is, but it's not always that simple.

    I have a Java app here I'm performance tuning for my PhD that allocates frequency hop sets to mobile phone networks. Running on a 2.2Ghz Athlon wih 512Mb RAM for a 15-transmitter test case takes an hour, it scales exponentially with transmitter size, and I want to address a 458 transmitter case. It's about 10^500 calculations, or it was before I started improving the algorithm. Even so, it's still going to be billions of iterations through the inner loop. Even a 1% speedup is hours off my runtime and that's a big thing for me.

    So when you dismiss all performance tuning with a wave of your hand, remember us poor beleagured scientists. We actually need all this stuff.
  • Not a bad albatross (Score:3, Insightful)

    by jemenake (595948) on Wednesday April 09 2003, @07:28PM (#5697752)
    Performance has been the albatross around Java's neck for a long time..
    Every time some C/C++ snob snipes Java for being slow, this is what I tell them:

    When I write a Java program... if it's too slow today, then, in time, the problem will go away without any more effort on the part of the programmer. In a year from now, we'll certainly have faster computers, which will make up for any speed problems.

    On the other hand...

    A year from now, we will almost certainly not have CPUs that are suddenly immune from dangling pointers and memory leaks.

    In other words, there are not plausible, near-future-forseeable advancements in computing hardware that could fix the worst problems of C/C++. Meanwhile, the near-future advancements in hardware are almost guranteed to fix Java's worst problem.

    The same holds true for doing your computing today... regardless of what hardware is available a year from now. Personally, I'd rather have a slow program that could keep running than one that was really fast, but crashed before I could save my work.
  • by mandrake*rpgdx (650221) on Wednesday April 09 2003, @12:31PM (#5693939)
    (http://pauljessup.blogspot.com/)
    I was looking on CNN and etc for a news report- couldn't find one.
    [ Parent ]
    • fuck off by mandrake*rpgdx (Score:1) Thursday April 10 2003, @07:38AM
    • 1 reply beneath your current threshold.
  • Re:Oxymoron ? (Score:3, Insightful)

    by Randolpho (628485) on Wednesday April 09 2003, @12:33PM (#5693947)
    (http://www.google.com/ig | Last Journal: Wednesday April 11 2007, @09:55AM)
    Amazingly, Java actually performs very well once the JVM loads. Sure, it can't match uber-efficient c code, but, let's be honest here, how much c code really is efficient? I'm sure it's less than c programmers like to believe. ;)

    That said, "slow" performing Java GUI aps are not so much the fault of the platform itself as they are the fault of the Java programmer's inability to deal efficiently with threads.
    [ Parent ]
    • Re:Oxymoron ? (Score:5, Interesting)

      by wfmcwalter (124904) on Wednesday April 09 2003, @12:58PM (#5694125)
      (http://www.mcwalter.org/)
      I don't quite know what it is that they've improved, but JVM startup time seems to have gotten dramatically better somewhere betweek JDK1.3 and JDK1.4.1. On my mainstream winXP machine I can have a text-mode java HelloWorld running to completion in 0.2 secs (tested using cygwin's "time" command). That's a huge improvement over the several seconds it used to take, and makes writing little command line utilities in java a practical prospect.

      Previously, the startup slowdown was due to the system having to load, verify, and link the twenty or so classes a simple program depends upon. Pjava and J2ME-CDC solved that by storing an image of the heap with the system classes already loaded, verified, and linked (and quickened) so the system was run-ready almost immediately. I wonder if the J2SE folks picked up on that? Alternatively, they could just be skipping the verify for those classes in the signed rt.jar, and offline preverify them prior to signature - the verifier always was the slow part of the process.

      Your point about threads is well taken, and applies more generally to much of java programming. Java's language and libraries make it all to easy to write architecturally-slow programs - you really still have to fully understand what you're doing in order to write a decent program, regardless of the language.

      [ Parent ]
  • Re:Don't use Java.... (Score:3, Insightful)

    by vingilot (218702) on Wednesday April 09 2003, @12:48PM (#5694028)
    (http://mtclimber.net/)
    Don't be an idiot. The size of the standard api does not relate to any inefficiency java has. How can the number of standard classes translate to inefficiency What is the magic number of standard classes to be "just right"?
    The best thing about java is the richness of the api. And the size of the documentation. C++/C should take a page from java's book in this department.
    You don't have to use the standard classes, go ahead and write the classes you need.

    Jonathan
    [ Parent ]
  • Re:Don't use Java.... (Score:4, Insightful)

    by boomgopher (627124) on Wednesday April 09 2003, @01:07PM (#5694212)
    (Last Journal: Friday November 26 2004, @05:49PM)
    Java would've been far better if they'd stuck to a few basic classes, and let people develop the classes they need as they go.

    Well, gosh, you go right ahead and write your own replacement classes for everything that Sun has done already. What's stopping you?

    That's exactly why I like Java. They have a lot of good built-in libraries that cover a wide-range of applications. I don't have to reinvent the freaking wheel every time I write an app.
    [ Parent ]
  • Re:So (Score:2)

    by machine of god (569301) on Wednesday April 09 2003, @01:29PM (#5694375)
    heh. Actually, it got a score of one, because it's in your preferences. You add 1 to people who log in. See, for me, they don't get that. Also, AC's get negative 1 rather than zero. It works out well to weed out people like me and you, I think.
    [ Parent ]
  • by egoots (557276) on Wednesday April 09 2003, @01:42PM (#5694514)

    By the way - how much of Google or Yahoo is written in Java... let's see - none of it.

    Every site makes their own choice of tools and technologies. Just because Google and Yahoo doesn't use Java, doesn't mean we can conclude it is useless

    Also, where does the "Gig of RAM per web page view" figure come from?

    [ Parent ]
  • http://industry.java.sun.com/javanews/stories/prin t/0,1797,16725,00.html ,
    http://industry.java.sun.com/javanews/stories/p rint/0,1797,23836,00.html

    yada yada yada

    Gig of ram per web view? You're totally clueless...
    [ Parent ]
  • Re:A warning sign (Score:1)

    by dracocat (554744) <dracocat@hotmail.com> on Wednesday April 09 2003, @05:27PM (#5696961)
    Agreed.
    Lets just remove needless things such as:
    • Genericity
    • multiple inheritance
    • assertion

    oh yeah, they already stripped those out before it was ever released.

    Actually I would much rather see a slower JVM and be able to have at least multiple inheritance. But alas, I am stuck with workarounds invloving interfaces.

    The huge market for Java tuning books is probably more acurately attributed to coders' over emphasis on software tuning.

    Tuning should be done wherever most time is spent in the software, not just willy nilly where a book tells you too.
    [ Parent ]
  • by Tukla (5899) <tukla_ratte@tukla.net> on Thursday April 10 2003, @04:17PM (#5705467)
    I've never heard this assertion before. Got a cite?

    How do you "rip off" something in the public domain? Doesn't "public domain" mean "no copyright"?

    [ Parent ]
  • 30 replies beneath your current threshold.