Slashdot Mirror


Java Urban Performance Legends

An anonymous reader writes "Programmers agonize over whether to allocate on the stack or on the heap. Some people think garbage collection will never be as efficient as direct memory management, and others feel it is easier to clean up a mess in one big batch than to pick up individual pieces of dust throughout the day. This article pokes some holes in the oft-repeated performance myth of slow allocation in JVMs."

121 of 846 comments (clear)

  1. Nonsense by hedge_death_shootout · · Score: 5, Funny

    These java urban performance legends are rubbish - java is highly performant in a rural or urban setting.

    1. Re:Nonsense by justsomebody · · Score: 2, Funny

      And it is no urban legend needed to tell me that Coffe wakes me up much faster than C++.

      --
      Signature Pro version 1.13.2-3 release 83.5 beta3try7 after-breakfast edition
  2. Robomaid by Doc+Ruby · · Score: 5, Interesting

    How much time have I spent with Electric Fence and valgrind finding memory leaks in my C programs? In Java, the auto garbage collection is as good as Perl's, without that tricky "unreadable code" problem ;). And I can always tune garbage collection performance by forcing a garbage collect when I know my app's got the time, like outside of a loop or before creating more objects in storage.

    --

    --
    make install -not war

    1. Re:Robomaid by Some+Random+Username · · Score: 3, Insightful

      If you spend alot of time using stuff like valgrind and searching for memory leaks, then you are doing something very wrong. Its really not hard to just free the memory you allocate. The fact that people can write entire operating systems in C without having these problems indicates that the problems are with people, not C.

    2. Re:Robomaid by Doc+Ruby · · Score: 5, Insightful

      Of course, that's why I program everything in machine language. Memory allocation in hex opcodes worked for me in 1981, it still works in 2005. Programming languages don't leak memory, programmers leak memory.

      In seriousness, look at the bugzillas and changelogs of any programming project. Memory leaks abound. So the reality is that memory de/allocation programming eats quite a lot of productivity, and impedes many otherwise ready releases. Of course we can de/allocate memory properly in C. And we can compute with scientific calculators. When we've got something better, we use it.

      --

      --
      make install -not war

    3. Re:Robomaid by AArmadillo · · Score: 3, Insightful
      The company I work for does development in mostly C/C++, and we haven't had a memory leak bug issued in 3.7 years according to our database. If memory leaks are your biggest problem, you probably aren't making effective use of smart pointers and structured allocation/deallocation.

      Also, let us not forget that java has memory leaks too and in my opinion they are much less obvious than C++ memory leaks.

    4. Re:Robomaid by Doc+Ruby · · Score: 2, Interesting

      I didn't say memory leaks are my biggest problem. The insufficiency of voice recognition and dataflow programming tools are my biggest problems :). But I still get memory leaks. And it still costs me more to hire programmers who don't generate memory leaks than to use their less-qualified peers and a JVM. If we programmed dataflow graphs, we'd spot redundant objects more easily. And voice recognition would let us drop them, without paying programmers to act as that middleware. A man can dream...

      --

      --
      make install -not war

    5. Re:Robomaid by Anonymous Coward · · Score: 2, Informative

      Actually, Java implementations are allowed to ignore System.gc() calls. It's just a suggestion to the runtime.

    6. Re:Robomaid by Mr.+Shiny+And+New · · Score: 5, Insightful

      You're right, Java does have memory leaks, in a sense, but these same problems can arise in any language. You could have a cache implemented in C/C++ that is never properly emptied, so over time it fills up. Or you could have a request log where, due to a bug, requests are not always removed from the log after they are processed. Sure, you might have included code to free the objects in the cache or log when you are done with them, but the programming error is that you forgot to remove the item. This is not a language issue, this is just a programming mistake.

      At least in Java you only need to worry about one problem: removing items from caches, logs, queues, etc when you are done with them; in C++ you have to also worry about de-allocating that object, which requires strict planning since the object must not be referred to anywhere else when you de-allocate it. In general you can't prove that the object isn't still referred-to by someone who had it before it was put into the cache/log/whatever; instead you need to establish rules and write documents to make sure everyone knows what the lifecycle of an object should be.

      As for your company not having a memory bug logged in 3.7 years, that's great, but without knowing what kind of applications you write, or how they're used, it's hard to say if that's significant. Some programs, like, say, grep, or mv or ls or any one-time-use utilities may be rife with memory leaks, but who cares? When the program terminates the memory is freed, and the user will likely not notice the leak. But even if your apps are long-running network services or whatever, I bet the time spent by developers preventing memory leaks is significant, even if that time is completely spread out throughout the development cycle instead of in large, easy-to-spot chunks running Valgrind or some other profiler.

    7. Re:Robomaid by Q2Serpent · · Score: 2, Insightful

      If you are hiring programmers who can't understand simple memory allocation and deallocation, you are more likely to run into a maintenance nightmare.

      Good programmers know how to write structured code that's easy to maintain, and a side effect of this is that memory allocation becomes second nature (like most other "problem": buffer overruns, memory leaks, etc). When you write good code, these problems rarely exist. The code structure sees to it.

      Just because Java tries to save you from one issue doesn't mean you can throw programmers with fewer skills at it and get the same result. Quality will suffer, because there are sill plenty of mistakes to be made in Java, and they all cost your bottom line just as much.

    8. Re:Robomaid by someone1234 · · Score: 2, Interesting

      Let's see the Java OS then :)

      --
      Patents Drive Free Software as Hurricanes Drive Construction Industry
    9. Re:Robomaid by Doc+Ruby · · Score: 3, Insightful

      Please forward me the resumes of these programmers, which include "Skills" like "I never write memory leaks". And whose "Certifications" include "Good Programmer", not those other resumes which say "Bad Programmer".

      The fact is that Java programs include more intelligence about programming from the compiler and the JVM. So programmers are more productive than with C. Which means that the same programmer budget can produce more product, or a lower budget can produce the same product. With distributed teams, outsourcing, OSS integration projects, those considerations are crucial to project success. Sure, quality projects also require good design and management. But Java eliminates some quality problems right out of the box. That can't be dismissed merely by saying "hire good programmers, not bad". Because it's a continuum, with a sliding scale of costs that isn't always proportional to productivity.

      --

      --
      make install -not war

    10. Re:Robomaid by Doc+Ruby · · Score: 2, Funny

      BZZT: Circular reference - you lose. Should've used javac.

      --

      --
      make install -not war

    11. Re:Robomaid by David's+Boy+Toy · · Score: 2, Insightful

      Java should really be compared to the STL in C++, not to C, or a bastardized C/C++ coding mix. Ideally new/delete/malloc/free should only be used in small pieces of low level code and fully encapsulated in an object.

      Much of Java code can be converted almost line for line to C++. Unlike Java, the STL can create containers of any type, including built in types, operating on them very efficiently.

      const size_t size = 500000000;
      std:vector<int> X(size);
      for(unsigned i = 0; i < size; i++)
      X[i] = random();

      std::sort(X.begin(), X.end());

      Compare the performance of this sort() operation to its Java equivalent. Compare the space used. Notice that at no point did we worry about having to allocate/free memory, its taken care of by the vector template. To be nice we presized the vector, but we didn't need to, we could have used X.push_back(random()) with some additional overhead from automatic resizing. Something like this matters alot in high performance application, a good example would be transforms of large sets of vectors in 3d games.

      Java is just another religion like LISP used to be, the CS purists are always chasing the holy grail of coding purity without regards to programming realities, yet Java is hardly even pure, its already got more evolutionary cruft than C++ and its around 1/3rd the age of the original C which has been evolved into C++.

      Rarely do I see real world Java code perform with any degree of efficiency, even when compared to Perl, let alone C++. A Java appserver is much larger and uses much more CPU time than a similarly complex one written in perl.

    12. Re:Robomaid by radtea · · Score: 4, Informative

      And I can always tune garbage collection performance by forcing a garbage collect when I know my app's got the time, like outside of a loop or before creating more objects in storage.

      No, you can't. At most you can give the JVM a hint that it would be nice to collect garbage now. The JVM is free to ignore that hint, and many JVMs will do just that.

      --
      Blasphemy is a human right. Blasphemophobia kills.
    13. Re:Robomaid by halleluja · · Score: 4, Funny
      The fact is that Java programs include more intelligence about programming from the compiler and the JVM.
      It is particularly sad the Visual PnP-generation of today cannot identify the merits of GOTO's and self-modifying code.

      I have never had any memory leaks, just by including the following code snippet:

      /* Distributed under GPL */
      #include <stdlib.h>

      static void* repo = malloc(100000000);

      int main(int argc, char** argv)
      {
      /* do stuff, just increment & cast *repo when I need to utilize free memory. */
      free(repo);
      }
    14. Re:Robomaid by Q2Serpent · · Score: 2, Insightful

      Productivity may be slightly hindered by the language (how easy is it to encapsulate functionality into easy-to-use packages), but I argue that it is dominated much more by the easy-to-use packages that are used.

      Java certainly helps here, but good libraries can be written in many languages. In fact, most libraries are written in C so that they can be used from many languages. A library written in C plus a small wrapper for the language-du-jour is a library usable from many languages. If you have good developers on your team, libraries will be written and re-used, and productivity will be high.

      Productivity comes from writing solid libraries so that you don't have to duplicate effort. Productivity comes from understanding how technologies work before you use them, so that you can avoid bug fixes, re-architecting the product, etc.

      My point is that a majority of productivity doesn't come from the language, and neither does a majority of the bug-avoidance. Java may help you in a few small ways, but if you are telling me that you'd rather have people with fewer skills just because you think Java will make up for it, you're mistaken.

  3. Java Urban Performance Legend #1 by GillBates0 · · Score: 5, Funny

    JVM memory allocation isn't "SLOW". It's just pleasantly unhurried.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
  4. They're good.. now.. by onion2k · · Score: 5, Insightful

    JVMs are surprisingly good at figuring out things that we used to assume only the developer could know.

    Yes they are. Now. 10 years ago when Java applets were being embedded in webpages (to show rippling water below a logo :) ) they weren't. The performance of the language has greatly improved while the perception of language has remained the roughly same (at least amoung the general coding community).

    Just goes to show that even if you have a great technical product you'll still need the marketdriods. Unfortunately.

    1. Re:They're good.. now.. by Mr.+Shiny+And+New · · Score: 3, Informative

      In some aspects, yes, it is much faster. For example, I can tell the difference between Java 1.4 and Java 5 (1.5) on the same hardware. My company's website was upgraded to Java 5 and performance increased significantly, mainly due to garbage-collection improvements. So I'd say that the same holds for the older JVMs. However, there may be other things added to the JVMs that make them less suitable for older hardware. I know that class libraries and app frameworks have gotten bigger as time goes on, so that would definately impact things in terms of memory usage.

  5. BULLONEY!! by Anonymous Coward · · Score: 3, Insightful

    These articles keep popping up flatly stating that Java's slowness is a myth. But, no matter how many times you say it is a myth and how hard you try to create a new perception, the FACT is that people's real-world experience, no matter how anecdotal, consistently demonstrates that Java is MASSIVELY slow than similar apps in C or C++.

    Java is slower. Don't even get me started on C#.

    1. Re:BULLONEY!! by HeaththeGreat · · Score: 4, Interesting

      What Java apps are you talking about?

      There aren't many professional-grade Java Desktop apps out there, and those that _are_ out there are generally built for maintainability, not speed (Eclipse, Netbeans). I built a Java web client that blew the pants off its older C++ version. The reason Java apps are generally slower is because the Java culture is about maintainence over performance.

    2. Re:BULLONEY!! by pla · · Score: 5, Interesting

      Don't even get me started on C#.

      I should hope not! Any form of benchmarking of Microsoft's .Net violates the EULA. And we wouldn't want that!

      So when Microsoft declares their interpreted inverse-polyglotic language as "faster" than compiled pure C, just accept it. Best for everyone that way.


      the FACT is that people's real-world experience, no matter how anecdotal, consistently demonstrates that Java is MASSIVELY slow than similar apps in C or C++.

      Well, the linked article contained a number of what I will graciously call "assumptions" (rather than "outright lies") about allocation patterns in C/C++ that simply don't hold true in most cases.

      For example, the parent mentions the old "stack or heap" question... Which no serious C coder would ask. Use the heap only when something won't fit on the stack. Why? The stack comes for "free" in C. If you need to store something too large, you need the heap. But then, you can allocate it once, and don't even consider freeing it until you finish with it (generational garbage collection? Survival time? Gimme a break - It survives until I tell it to go away!). As for recursion... You can blow the stack that way, but a good programmer will either flatten the recursion, or cap its depth.


      And the article dares to justify its "assuptions" by comparing Java against a language interpreter such as Perl. Not exactly a fair comparison - Yes, Perl counts as "real-world", but in an interpreter, you can't know ahead of time anything about your memory requirements. At best, you can cap them and dump the interpreted program if it gets too greedy. Now, some might point out that Java gets interpreted as well - And I'll readily admit that, for doing so, it does a damn fine job with its garbage collection. But if you want to compare Java to Perl, then do so. Don't try to sneak in a comparison to C with a layer of indirection.


      One last point - The article mentions that you no longer need to use object pooling. SURE you no longer need it - Java does it implicitly at startup. You can avoid all but a single malloc/free pair in C as well, if you just steal half the system's memory in main(). Sometimes that even counts as a good choice - I've used it myself, with the important caveat that I've done so when appropriate. Not always. I don't have malloc() as the second and free() as the second-to-last statements in every program I write. And that most definitely shows in the minimal memory footprints attainable between the two languages... Try writing a Java program that eats less than 32k.

    3. Re:BULLONEY!! by LarsWestergren · · Score: 3, Informative

      The stack comes for "free" in C. If you need to store something too large, you need the heap. But then, you can allocate it once, and don't even consider freeing it until you finish with it

      Or NOT consider freeing it when you forget about it... as the case may be.

      Try writing a Java program that eats less than 32k.

      No problem at all.

      --

      Being bitter is drinking poison and hoping someone else will die

    4. Re:BULLONEY!! by pla · · Score: 4, Insightful

      Or NOT consider freeing it when you forget about it...

      Programming takes some level of skill.

      If you "forget" to increment a pointer, it won't have advanced the next time you use it. If you forget to open a file, assuming your program doesn't crash, anything you write to it goes to the bit bucket.

      If you forget a wife' birthday, you'll have a pissed-off wife.



      "Try writing a Java program that eats less than 32k."
      No problem at all.

      Uh-huh... Now do the same thing without needing a special, stripped-down, nearly featureless JRE. I don't need a special build of GCC to satisfy the condition, why did we shift from apples to oranges to make it possible in the Java world?



      And most of these points end up exatly there - Apples and oranges. Java can do better than a few worst-case scenarios in C. Java can fit in a sane amount of memory with special builds. Java can outperform C by-way-of Perl. All nice claims, but self delusion doesn't make for better programmers.

    5. Re:BULLONEY!! by gaj · · Score: 5, Insightful

      It's not really apples to oranges to use a smaller profile JRE for creating smaller profile programs. The JRE includes libraries and features such as threading and such. Let's see you build a C program that uses pthreads and one or two major libraries and still have your memory use come in under 32K. Remember, apples to apples, right?

    6. Re:BULLONEY!! by earthbound+kid · · Score: 4, Insightful

      Programming takes some level of skill.

      If you "forget" to increment a pointer, it won't have advanced the next time you use it. If you forget to open a file, assuming your program doesn't crash, anything you write to it goes to the bit bucket.

      If you forget a wife' birthday, you'll have a pissed-off wife.

      I'm not about to forget my girlfriend's birthday, because my computer warns me about it three days ahead of time. Similarly, why should we risk forgetting to deallocate stuff from the heap, when we can have the computer do it itself? Yes, programming takes some skill. But we shouldn't start programming using only our thumbs while dangling over a pit of lava, just to up the skill factor needlessly. If we're going to do something more difficult, we need to get a benefit for it. The benefit of not using a garbage collecting language is that your code will probably be slightly faster than the equivalent code in a GC language. But, is that slight performance increase worth the pain in the ass of doing it the manly way? In most cases, not really. But hey, judge for yourself: find the best language for your particular job and forget the rest.
    7. Re:BULLONEY!! by sjasja · · Score: 2, Insightful

      > And the article dares to justify its "assuptions" by
      > comparing Java against a language interpreter such as Perl.

      Err... what? The article mentions Perl once, as an example of a C application.

      The article says if you run that particular application you'll find that it spends 20-30% of its time in malloc() and free(). The points being that allocation speed matters in real applications, and that malloc+free is pretty slow.

      > Try writing a Java program that eats less than 32k.

      Lots of cell phone games manage to do this.

    8. Re:BULLONEY!! by matfud · · Score: 2, Interesting

      And when resources get really tight C is no longer an appropriate language to use. Many microcontrollers have less then 128 bytes of ram to work in. Often the program has to be stored in less then 256 bytes of ROM. C does not cut it in those environments. Welcome to our assembler overlords. C also has to be cut down to run on these low end devices. floating point divisions, 32 bit mulitplications, 16 bit additions...well they are not supported. The J2ME IS cut down. However it does specify a basic set of operations you must implement on the chip (or emulate in a layer in software)

      "Remember, with Java you still have the overhead of a virtual machine. And that counts towards program and resource size (sometimes, significantly)."

      The processors I'm playiung with at the moment run java byte code natively. You would have to have a virtual machine to run C on them. Rememeber, C is only efficient in some situations because the bytecode (machine code) it produces maps directly to the platform it is running on. Java and other "interpreted" langauges are designed to run on a machine that you may not have, so generally they are run on an interpreter. That does not mean that a machine to run the code directly does not exist.

    9. Re:BULLONEY!! by jma05 · · Score: 2, Insightful

      No! Python (or Ruby or Perl) programs run FASTER than Java programs. That's despite pure Python being much slower than pure Java. Don't focus too much on benchmarks. They don't give a big picture. Python IDEs ARE MORE RESPONSIVE than Java IDEs. Take a look yourself.

      That's because much of the cycles in a Python app are spent in optimized native code rather than in Python's byte code.

      All Python GUI apps are faster because they are wrappers around fast C/C++ toolkits rather than pure byte code like Swing. If someone were to reimplement Swing in Python without using an external toolkit, it will no doubt be slow. But that is not the culture in Python. Same goes for most programming in Python. In fact, almost as a rule, anything where performance matters for Python apps, you have a C extension.

      There is an advantage to Java's approach. Pack everything into a jar and it will run anywhere. With Python, I will have into seperately ensure that wxPython, numarray etc are installed for each platform since they are native extensions. However I never had a problem with that since they are available for both the platforms I use (windows and Linux) easily. If you use an exotic platform, you will have compile for it.

      So while your code in Python will be portable, the dependencies are not always automatically. But I am happy with this trade off.

  6. As I see it. by Z00L00K · · Score: 3, Interesting

    The memory allocation management routines are normally running when the JVM thinks it's best, but as a programmer it is usually possible to predict the best time when to actually take care of the housekeeping. Even if the memory management cleanup takes the same time in both cases Java has a tendency to issue them in the middle of everything. So if I as a programmer does the garbage collection at the end of a displayed page and Java does it uncontrollable in the middle of the page the latter case is more annoying to the user.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
  7. Article somewhat ignores the fatness of the JVM by expro · · Score: 4, Informative

    How many JVMs can you afford to run on your system for different apps, and how can you make sure they are all the right size, the garbage collectors are in an appropriate mode that can keep up with generated garbage, etc. I can run lots of native apps, which in many cases have no need for a significant heap like Java brings into the picture in far less space than a single JVM. A JVM runs much heavier on the system, and when I run Netbeans, it is continuously on the verge of eating my 1.2 GB powerbook alive, in fact I have to frequently restart Netbeans to get memory back. It has a long way to go in real practical terms even if they have theoretical solutions to some of the problems. I am porting my server software away from Java for the same reasons. This is JDK 1.4, and I am about to try it on 1.5, but I don't think there is that much difference.

    1. Re:Article somewhat ignores the fatness of the JVM by LarsWestergren · · Score: 4, Informative

      How many JVMs can you afford to run on your system for different apps, and how can you make sure they are all the right size, the garbage collectors are in an appropriate mode that can keep up with generated garbage, etc.

      Try "java -X". You will see that you can decide what the "right" size is. See this link, a guy forces the JVM to run a web server on 16 mb of memory and still get decent performance.

      --

      Being bitter is drinking poison and hoping someone else will die

    2. Re:Article somewhat ignores the fatness of the JVM by expro · · Score: 2, Insightful

      And the command qualifiers claim the same thing in a ps view of the system, but the memory consumed rises towards 1GB. This is not unusual where Java is concerned. I have run JVMs for years and never found one willing to live within its bounds.

    3. Re:Article somewhat ignores the fatness of the JVM by Bastian · · Score: 4, Insightful

      Manually determining how much memory to give to an application was one of the things that us Mac users were more than happy to leave behind with the transition to OS X. Hell, we were more than happy to kill that "feature." Dancing on its coffin and all that. Are you seriously suggesting the world go back?

      Besides, I thought the biggest examples of Java was that it was all cool and dynamic and took care of things for you. It seems fair to me to expect such a language/platform to be smart enough to figure out that it's not polite to walk to the buffet, heap three plates with a ridiculous pile of food, and go back to the table and graze on a few pieces of celery, leaving the rest of the food untouched.

    4. Re:Article somewhat ignores the fatness of the JVM by Bastian · · Score: 2, Insightful

      Having it be something I have to think about is what's wrong with it. Duh. This is 21st century desktop computing we're talking about, for goodness' sake. Be a good neighbor. Start with a small memory footprint, and grow it if you need to. Just like a native app.

  8. Article Actually Argues Something Else by PepeGSay · · Score: 5, Informative

    This article is actually debunking some people's reasons why Java has poor performance. It does little to debunk my actual real world experience that it *is* slow. I'm glad to see that performance has increased alot, but I remember some all (well 90% or something) Java applications, like the original JBuilder, that made me want to claw my eyeballs out when using them. Those apps and other early apps are where Java's performance issues really took hold in many people's psyche.

    1. Re:Article Actually Argues Something Else by NeoBeans · · Score: 3, Insightful
      I remember some all (well 90% or something) Java applications, like the original JBuilder, that made me want to claw my eyeballs out when using them.

      Valid point... for 1999. But Java has been through a lot of changes since "the original JBuilder" came out. There have been three major changes to the class libraries (1.2, 1.4, and the 5.0).

      Honestly, I understand why people are down on Java -- it's because there have always been two strengths to the Java "platform":

      1. It provides a simple programming model (single inheritance, indirect memory management, ...)
      2. A rich class library for specific tasks that are easy to learn (but difficult to master, obviously).

      ...and early implementations weren't able to keep up with native code in any way, shape or form.

      That said, I think you hit the nail ont the head -- people are still thinking in terms of 1999 and not 2005 when they think of Java -- at least on Slashdot. But the typical Java developer is busy writing enterprise apps, not writing kernel code, device drivers, or anything else that requires C/C++.

    2. Re:Article Actually Argues Something Else by hobuddy · · Score: 2, Insightful

      Odd, then, that NetBeans and Eclipse are still slower than a sedated elephant on my Athlon 64 3200+ with 512 MB RAM. My computer must be living in a time warp.

      Or maybe the truth is that Java is "effectively sluggish, though not technically slow" because its runtime optimization techniques require such huge amounts of RAM.

      Although I'm well aware of the limitations of the Great Computer Language Shootout as a tool for measuring a language's overall utility, it does tell the naked truth about performance. When I see an easy-to-use language whose design makes it easier to write reusable code than Java using somewhat less CPU time and typically FOUR TIMES less memory , it makes me suspect that well-intentioned Java apologists like you have never really attempted an objective evaluation of the performance compromises inherent in Java's design.

      --
      Erlang.org: wow
    3. Re:Article Actually Argues Something Else by alan_dershowitz · · Score: 2, Interesting
      Odd, then, that NetBeans and Eclipse are still slower than a sedated elephant on my Athlon 64 3200+ with 512 MB RAM. My computer must be living in a time warp.


      It must be, so far I'm running Eclipse and/or Oracle JDeveloper on all the following platforms with no problems:


      Dell P4 2Ghz 512MB RAM, Windows 2000
      Toshiba P4 2Ghz laptop 512MB RAM, Gentoo Linux (2.6 kernel)
      Athlon XP 1900, 1GB RAM, WinXP/Gentoo Linux dual boot


      I will give you a caveat. JDeveloper was pretty crusty until version 10G came out. Runs pretty nice now. Eclipse is no problem on any of them. If you are doing Struts development, I can tell you that I was occasionally running out of RAM at 512MB. Of course, I'm running JDeveloper, a J2EE server, and my app all at the same time, so that's not too crazy.


      I'm not saying they don't run like crap on your machine, I have no idea. All I know is that the company where I work, we have a few hundred people with the exact same machine specs that I do, and we don't have the problem that you are having.


      All these things eat the shit out of resources, but they do not run slow, so I half agree with you, and I half don't. I don't know what the problem is that makes it take up all the resources, but java is not slow. I've been playing with JOGL, an OpenGL java wrapper library, and no one would mistake the results for slow. Maybe this is unfair, but rendering 2D OpenGL in Java is WAY faster than rendering native GDI in Windows.

  9. Re:Counter arguments by LarsWestergren · · Score: 4, Insightful

    You so called counter argument is 6 years old... a lot of it weren't true to begin with, and a lot of things have happened since then.

    In the end though, the MOST important thing is that these days, processor cycles are cheap. Programmer cycles are expensive. Therefore it makes sense to sacrifice a little bit of program performance to get more productive programmers.

    --

    Being bitter is drinking poison and hoping someone else will die

  10. The problem I have is that by bhurt · · Score: 4, Informative

    the people who keep telling me allocation in Java is slow (much slower than 10 instructions) are generally experienced Java programmers. I use Ocaml, so I'm quite aware of how fast a generational garbage collector can be (btw, on the x86 in Ocaml, allocations are only 5 simple instructions). But from all first hand reports I've heard, Java allocation is still slow. It may be faster than C++, but it's still slow.

    1. Re:The problem I have is that by ucblockhead · · Score: 3, Insightful
      In C++, it only requires 1 instruction to allocate on the stack. Less than that, actually, if you are allocating multiple objects in one scope.

      You can't just compare Java allocation to:

      Foo *foo = new Foo();

      You also have to compare it to:

      Foo foo;

      Experienced C++ programmers will prefer the latter both because it is faster and because you don't have to worry about freeing it. One of the problems with a lot of the "See, Java's faster than C++!" comparisons is that they tend to translate directly from Java to C++, ignoring the things you can do in C++ but not Java (like stack allocation) that have a huge performance impact.

      --
      The cake is a pie
    2. Re:The problem I have is that by Anonymous Coward · · Score: 2, Insightful

      But from all first hand reports I've heard, Java allocation is still slow.

      Kep in mind that allocation in Java also includes initialization. Arrays are zeroed, object references are nulled etc. This is a good thing in general but it sure does not make allocation any faster.

  11. Re:Counter arguments by Anonymous Coward · · Score: 2, Funny

    Programmer cycles are expensive.

    Not if you're counting in rupees.

  12. If I had a dime for everytime I heard that.... by ShyGuy91284 · · Score: 2, Interesting

    I've had many professors say that Java is nowhere near as slow as it used to be, and that it was just a myth now that it is that much slower the C or another language that doesn't rely on VMs. In most applications, I guess it's actually equal enough to C to be considered as an alternative. Although it doesn't have anywhere near the rich number of libraries C/C++ works with (I'd like to see someone make a cutting edge game in Java).

    --
    In undeveloped countries, the consumer controls the market. In capitalist America, the market controls you.
    1. Re:If I had a dime for everytime I heard that.... by LarsWestergren · · Score: 3, Informative

      (I'd like to see someone make a cutting edge game in Java).

      There are lots of games done in Java, mainly for mobile phones through J2ME. A few of them might have cutting edge gameplay (though I've yet to see one), but it is unlikely to see cutting edge graphics. Still, there are some pretty impressive things you can do with JOGL.

      --

      Being bitter is drinking poison and hoping someone else will die

    2. Re:If I had a dime for everytime I heard that.... by eraserewind · · Score: 3, Informative

      On the graphics thing, I don't see why not Java. Next gen phones will have HW accelerated 3d graphics. Check out the TI OMAP 2420 embedded multimedia processor specifications for a look at what the future may bring.

    3. Re:If I had a dime for everytime I heard that.... by jmccay · · Score: 2, Insightful

      I've had many professors say that Java is nowhere near as slow as it used to be, and that it was just a myth now that it is that much slower the C or another language that doesn't rely on VMs. In most applications, I guess it's actually equal enough to C to be considered as an alternative.

            Have they used the same machine to compare the performance, of all the different versions, on each time they compared? Also, how fast was the machine? I have a feeling that some of the people are comparing Java using fast computers with a lot of memory. I have 3 (usuable) computers: 1 P2 350, 1 P3 900 (loaner), & 1 P4 3G. I would not even want to try to run a complex java application on the P2 & P3 machines. The P4 is fast enough where using a VM is not going to make a difference. If you want to compare a Java to C++ use a slower machine (less than a gig speed & memory) it's more realistic of what people might have at home. C/C++ will win hands down on slow machines. I might also note that this article is from IBM Developer works which continually promotes Java, and I doubt it's in the there best interests to say C++ is better.

      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
  13. First! by Anonymous Coward · · Score: 5, Funny

    First post here from my Java workstation. Take that!

  14. Re:Doesn't poke holes at all by fish+waffle · · Score: 2, Informative

    But all the examples in the article aren't tested in practise. Maybe the escape analysis the author describes works as advertised. But without actually testing and analysing real code produced and without actual benchmarks the article doesn't proof a thing

    The author is giving you a high-level, greatly edited view of some of the major optimization techniques in use today. The original academic/technical papers on which that is based demonstrate/measure their techniques on various benchmarks.

    One thing the author seems to forget is that you would at least need a fallback mechanism when a method is overridden in a subclass

    This is well-known. Code-patching, on-stack replacement, pre-existence etc are used in production jits to recover from that kind of thing. This paper has a decent summary of current approaches:

  15. The performance red herring by MarkEst1973 · · Score: 4, Insightful
    The laws of optimization are:

    1. Make it work.
    2. Make it work well.
    3. Make it work fast

    And #3 is the most interesting... how fast is fast? In an absolute sense, sure, C/C++ will always be faster. But does the end user notice this in a webapp? NO!

    I have a p3 450mhz box running Tomcat/MySql. It serves my local applications fast enough. The server can render the page much more quickly than my browser (on a p4 1.5ghz box) can render it. As a webapp, java on an old machine is plenty fast.

    Java as a desktop GUI is an altogether different story, but I'm not using java on the desktop. This point is moot to me.

    "Fast enough" to not be noticeable. That is the secret of #3. In a webapp, this is easily achieved in java.

    1. Re:The performance red herring by ucblockhead · · Score: 2, Insightful

      The thing is that programs don't sit around doing nothing but allocation. (If the speed of memory allocation is a factor in your program's speed, you have worse issues the language!) One of the big areas where Java performance fails is in its collection classes. The STL containers run much faster than the Java containers. This is inherent in the design. The Java containers will always be slower because of the "container of Objects" design. Sun could have fixed this with generics, but they chose to layer it on top of their "container of Objects" design rather than making it an alternative (as Microsoft did with C#.)

      This is important because the speed of most application programs spend most of their time manipulating data structures.

      Also, you're running bytecode, so you're automatically running at half-speed. Yes, JIT and optimization can recover some of this, but you can't ignore the effect.

      Last time I used Java, one of the problems was that the garbage collector tended to lock everything for a significant period (0.5-1 second) even though the average deallocation time was smaller. If this happens in a GUI event, the UI will lock for a noticible period making the app seem slower even if in terms of CPU usage it isn't. More modern garbage collectors may have fixed this. I have no idea. But average deallocation speed is not the only metric you have to look at. You also have to look at the peak time. free may be slower, but it'll never take an exceptionally large amount of time.

      --
      The cake is a pie
  16. Interesting, but I doubt it'll work by vadim_t · · Score: 3, Interesting

    The copying collector sounds really fast indeed, but I can immediately see two problems:

    The first one is the need for a huge amount of memory. It would seem that the optimal way of dealing with this is restricting the amount of memory available to the application, otherwise any app can grow to the maximum size allowed by the VM, whether it needs it or not. But this sounds rather crappy to me, now every developer needs to figure out an right limit for the application.

    The second is that performance is going to suck when garbage collection is performed. The slowdown could be a lot larger than a single execution of malloc/free, especially if virtual memory is taken into account. The unused half of the memory will often be quickly moved to swap by the VM, especially when the process grows to sizes in the order of hundreds of MB. Then GC will force bringing all that back to RAM, while possibly swapping the previously used half to disk. Exactly the same situation as what's described with heap allocation, but a whole lot worse.

    It sounds to me that even if malloc is slower, it's a lot less inconvenient in applications like games, where something that is always slow can be taken into account, but where a sudden run of the GC could be really inconvenient.

    But this is not my area of experience, so it's just what came to mind. Can anybody confirm or refute these suspicions?

  17. This is Not News by putko · · Score: 4, Interesting

    Here is a paper (PostScript) from 1987 on the topic of GC being faster than manual allocation.

    The author went on to make a very fast GC that set speed records.

    If you are looking for factual arguments, with performance measurements and so on, just look at his work over the last few decades -- you'll see he did a lot of work in these very practical areas.

    When you see how productive guys like him can be, it makes me wish that some people would just stay alive, and keep working, for a few hundred years more, instead of our typical mortal lifespans.

    --
    http://www.thebricktestament.com/the_law/when_to_s tone_your_children/dt21_18a.html
    1. Re:This is Not News by Sirch · · Score: 2, Funny

      "When you see how productive guys like him can be, it makes me wish that some people would just stay alive, and keep working, for a few hundred years more, instead of our typical mortal lifespans"

      ... but that would be circumventing God's garbage collector! Just as in Java, when God has no more use for you, he'll "collect" you on his own timetable.

      Of course, you could always suggest someone is collected with a shotgun...

      Laugh, funny etc.

  18. Re:Counter arguments by Michalson · · Score: 5, Insightful

    Then use Delphi, or better yet, C#. (or even Python and a few other choices)

    Faster productivity, less bugs, no ram guzzling 5 minute startup. Java isn't the only language that reduces development time, it's just the only one (besides VB) that makes you sacrifice big things to get it.

  19. good programmers by willCode4Beer.com · · Score: 5, Insightful

    A *good* C++ programmer will probably write code that outperforms the equivalent in Java. A *good* C+ programmer will remember to deallocate all of his objects to prevent memory leaks. A *good* C++ programmer will copy his strings correctly to prevent buffer overflow exploits.

    If you have been involved in developmnent for any reasonable amount of time or worked on projects of reasonable size, you know that *good* programmers are hard to come by. When you add the real world to the picture you find that simple things like garbage collection and a virtual machine can make a mediocre java programmer outperform a mediocre C++ programmer.

    If schools actually learned to produce good programmers, and HR departments learned how to identify them, and job interviews verified them, we wouldn't be having this discussion.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    1. Re:good programmers by carlislematthew · · Score: 3, Informative
      You're absolutely correct, except perhaps in the last paragraph. Programming is as much about aptitude as it is about education and experience. Some people will *never* be good programmers no matter what you do with them.

      I have programmed (in many different languages) since I was about 9 and regard myself as a good programmer - who doesn't? ;) Anyway, I now hire and manage programmers and have interviewed probably about a hundred people for programming positions. Most of them are total shit. They couldn't program their way out of a paper bag. Their resume looks great and they have all the acronyms and say the right things. Then I ask them to code a function to reverse the order of a string with allocating as little extra memory as possible. Less than 50% of people can do it right. A simple algorithm like this is easy to check in your head and they just don't get it.

      One of the other more "nasty" questions I ask is for people to do a number to hex-string conversion algorithm. I've only have ONE person do it right. Most just stare at me. They don't understand binary! They mostly have CS degrees so they were taught, but their brains don't really get it. It's very interesting because most people don't understand what a number is at a base level - it's astounding. I could go on...

    2. Re:good programmers by GuyWithLag · · Score: 2, Interesting
      Also, your using a tiny bit more memory than you need to (at least 1 int without compiler optimization) because i++ expands to i = i + 1 which means you need a copy of i, if you used ++i which expands to inc i then you don't need a copy.

      Hear that glass breaking? That's your credibilty going out the window... The statement i++; where i is an int will produce exactly the same code with ++i; and i=i+1; on an optimizing compiler, and no extra memory (or registers) will be used. Note that i is an int, not an object with overloaded operators...

      Here's a problem: write the same programm, but don't use any extra variables.
    3. Re:good programmers by Henry+V+.009 · · Score: 2, Insightful
      #include <string>
      #include <algorithm>
      using namespace std;
      int main(void){
      string s("Please reverse me");
      reverse(s.begin(),s.end());
      }
      What do I win? (Better be a job.)
    4. Re:good programmers by carlislematthew · · Score: 2, Interesting
      In an interview, I used to tell people that they could use strlen, but not other string functions. I stopped telling people that a couple of years ago and sometimes people give a solution like yours. If you weren't an axe murderer and you actually gave me the real solution afterwards (after I clarify I want *you* to implement it), then you'd definately be in the running to get a job. :)

      BTW - your solution allocates about 4 squigabytes of memory, but that's OK because it all gets allocated by someone else, so it doesn't count. ;)

    5. Re:good programmers by Henry+V+.009 · · Score: 2, Informative
      Okay, you have intrigued me. Here is my solution. No extra memory needed for a temp variable due to a dirty trick. But I strongly advise you not hire anybody who does this. There will be tears.
      #include <cstring>
      int main(void){
      using std::strlen;
      char c[] = "Please reverse me";
      int length = std::strlen(c);
      for (int i=0;i < length/2; ++i){
      c[length] = c[i];
      c[i] = c[length - 1 - i];
      c[length - 1 - i] = c[length];
      }
      c[length] = '\0';
      }
      Also, I'm afraid that I'd never get the interview. No coding experience and have never taken a class in it. Fun hobby though.
    6. Re:good programmers by carlislematthew · · Score: 2, Informative
      Yes, you'd probably never get an interview. If someone has zero experience *and* zero "official" education then it's difficult to get an interview for a job programming.

      However, your solution is interesting. Using the null termination for your temporary space is an interesting way of saving a byte. But you're right, I'd prefer an actual variable to be used.

      Ever considered a career in programming?

    7. Re:good programmers by baadger · · Score: 2, Interesting
      This little discussion tree is flooded with code each with various advantages and disadvantages... so of course I felt the urge to investigate the problem myself and contribute something.

      I started off looking at the x86 instruction set and then googling for "XCHG reverse string" and voila, came up with this page that, aswell as covering some some of the methods described in this little discussion tree, has a final comment thats extra-specially interesting:

      In practice, for most compilers on Intel hardware the code

      int tmp;
      tmp = *b;
      *b = *a;
      *a = tmp;

      will compile into a single XCHG instruction. However, most compilers will not figure out the equivalent

      b ^= a;
      a ^= b;
      b ^= a;

      Ham Fisted
      Saturday, August 21, 2004


      Of course, if you didn't trust your compiler (or working toward multiple architectures) you could always use some compiler directives and some embedded asm?

      Is it possible to write this function using nothing but reigsters and the memory occupied by the string? Anyone care to give it a go? >)
    8. Re:good programmers by man_of_mr_e · · Score: 3, Insightful

      Unfortunately, asking a interviewee to write code on the spot only tests the interviewees critical thinking capabilities. No their programming skill.

      When an interviewee comes to an interview, his state of mind is on passing HR related questions. He's prepared for questions like "Why did you leave your last job" or "What's your greatest flaw", not writing code on the spot.

      Most programmers I know have to be "in the zone" to write good code, and can't just jump from one mode to another instantaneously. That's why programmers need to be given nice quiet areas and left alone for long periods of time to get stuff done. Constant interruptions and distractions prevent them from being "in the zone".

      While critical thinking may be a good trait, it's not a very common one, especially to programmers. Maybe THAT is why so few of them can do what you ask, not that they're incapable, but rather that they just weren't expecting it and can't switch gears that fast.

    9. Re:good programmers by scotch · · Score: 2, Funny
      I fail to see how I was rude or boastful. Perhaps you are too sensitive? As an interviewer, I am receptive to criticism that will help me conduct more productive interviews.

      Though we have common ground in our opinion of the XOR trick, I guess we can agree that you'll never hire me and I'll never work for you. I can live with that arrangement if you can. Just to make sure you don't accidently hire me, whenever you interview, ask the question: "Are you willing to have sex for promotions?". I will repsond: "No, but I'll put out for a better office". That way, you'll know it's me, and I'll know it's you.

      --
      XML causes global warming.
  20. Re:Counter arguments by mikaelhg · · Score: 5, Interesting

    Programmer cycles are expensive.

    Indeed. It might be worth (pardon my pun) reiterating what those cycles really are, in regard to application performance.

    In all languages I know of, you get some library functions ready-made, and you need to code some stuff yourself.

    Most performance problems occur in the code you made yourself.

    In my experience, you get most bang for buck when you are able to efficiently allocate your programmer time to a) program a functionally complete draft version, b) optimize those parts which need optimization and c) maintain the program, in a manner which is BALANCED, but biased towards maintenance.

    De facto, you get better balance between those things, and most bang for buck, using languages such as Java, as opposed to languages such as C++, because (say) Java offers a pretty coherent conceptual framework (class libraries) for creating your draft in a maintainable way, provides default access to excellent non-invasive performance measurement tools such as YourKit and JProfiler which let you objectively find out where you need to do performance work.

    This means you can do only the optimization work that is necessary, and create optimized packages which extend the default class library interfaces which means that generally maintenance programmers don't have to put nearly as much work into figuring out how the optimizations affect the draft work.

    It's not perfect, but it gets you more bang for buck, which is what matters to you when you manage resources.

    Not the default developer perspective, I know.

  21. Really? by Mark_MF-WN · · Score: 4, Informative

    Really? Can provide a few REAL world examples? Can you name one? Personally, I'm running Azureus and Netbeans right now, and they're not perceptably different from C++ desktop applications like KDevelop or OpenOffice.

  22. Java memory allocation vs. malloc by iambarry · · Score: 5, Interesting

    The article's main point is that Java's memory allocation is faster than malloc, and it's garbage collection is better than cumulative free's.

    However, thats not the problem. All memory in a Java program has to be allocated dynamically. Other languages offer static memory alternatives. Static memory use will be more efficient in many cases.

    The my language is faster than yours argument is inherently stupid. There is no "best" language. You need to use the right tool for the right job.

    --Barry

  23. Truth vs Perception by SmallFurryCreature · · Score: 2, Insightful
    I don't code in java so my only experience with it is through applications. Most notably Freenet and Azureus and Eclipse. All are brilliant apps that absolutly excell at what they do. There is however not a single person that can with a straight face claim that these programs do not hog resourcers like a .... well like a java app.

    Simply put there may be fast efficient tiny java programs out there but I don't see them. I don't really care about how garbage is collected. All I care is that a simple editor gobbles up memory like it was some kind of FPS. Sure I love the fact that I can use the same editor with the same extensions (to a point) on my home linux machines and work evil OS machines BUT it comes at a price and that is a lot of memory.

    Perhaps Sun has indeed improved java massivly over those horribly slow and crashing java applets we had a few years ago that were so going to take over the net by storm. Perhaps all the problems are just due to certain public java programs being badly written.

    It doesn't matter, java is slow, c is fast. Instead of having written this article perhaps the author should have examined some common java memory hog programs and analyzed wether the fault lies with java OR the coding in question OR and this is an option few consider, that JAVA apps and C apps are often compared like apple and oranges. Azureus vs Bittorrent (a tiny and far simpler app) Eclipse vs VI etc etc.

    A lot of languages deal with mis-reprensatation. I don't exactly feel sorry for the bad rep that java has as many java fanboys happily spread un-truths themselves. Like java vs PHP vs ASP for web development. Judging from my own experiences all this is just one giant "Your mom is so fat ...." competition.

    --

    MMO Quests are like orgasms:

    You may solo them, I prefer them in a group.

    1. Re:Truth vs Perception by the+eric+conspiracy · · Score: 2, Interesting

      Simply put there may be fast efficient tiny java programs out there but I don't see them.

      If Java was as bad as you say it would NOT be so popular in embedded devices. There is a huge disconnect between the archaic concept of Java as a slow pig and the real world popularity of Java on small systems like printers and cell phones.

    2. Re:Truth vs Perception by Dogtanian · · Score: 2, Informative

      If Java was as bad as you say it would NOT be so popular in embedded devices. There is a huge disconnect between the archaic concept of Java as a slow pig and the real world popularity of Java on small systems like printers and cell phones.

      Doesn't that use J2ME though? And, I would assume, J2ME gives you less facilities than J2SE and J2EE, so are we comparing like with like?

      Not saying, you're wrong, I just want to know if the comparison is valid.

      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
  24. Fire and forget memory management by defile · · Score: 2, Insightful

    I think automatic garbage collection is great, but _my_ problems with Java's memory allocator have little to do with performance. Rather, it sucks so hard at dealing with out-of-memory conditions.

    Why would you ever run out of memory? If you're on a microcomputer, you tend to have an arbitrary limit anyway. The JDK default is 64MB max heap. This is to prevent runaways, but setting the heap size to some arbitrarily high number has really awful performance characteristics -- god help you if you set the number higher than the amount of RAM you have available, or applications that want to share the machine. There's a whole other rant about how stupid automatic garbage collection is on a timeshared environment (like a server), but it's not the point I want to make.

    The point I want to make: since Java is supposed to run everywhere, you really can find environments where you only have 1 or 2MB of heap to play with. Having constrained resources is nothing new to programmers, they've been dealing with it forever. But Java's allocator combined with constrained resources leaves you with very little wiggle room.

    If you've ever developed a Java applicatoin that manages an in-core cache you might have experienced how fucked you are when you get around to the logic of cache expiration. Ideally you can keep cache forever, as long as a) you know it's not stale, and b) you don't need the memory for something better. A is not a problem in Java, but setting up a system to facilitate B is actually really hard. In C/C++ you can wrap malloc() so that if it fails, you can start dumping cache until it succeeds. The solution is elegant, dare I say beautiful.

    In Java this is totally impossible. When you run out of memory the garbage collector is tripped, and if it can't free anything up it generates an OOM exception. You can't realistically catch these exceptions -- they can bubble up from anywhere at any time. The only place you can catch them is at the top of your program loop and the only good it does there is let you say "OUT OF MEMORY" in a user friendly way before exiting the application -- assuming you have the resources left to even say that of course.

    So how does this effect your cache model? Well, you end up having to guess at how much cache to maintain. Guess too high and your application breaks when it's run in a low memory environment. Guess too low and you're not caching enough, the user experience suffers when it has no reason to. The above scenario is just one example.

    Essentially, the problem is one of prioritized memory. Java gives you no usable way of saying memory allocated for purpose X is fine as long as purpose Y is not short. Designers and apologists can make excuses for why Java doesn't support this and maybe provide a good reason, but those reasons hardly qualify Java as a general purpose programming language.

    Goto also.

    1. Re:Fire and forget memory management by Mr.+Shiny+And+New · · Score: 2, Informative

      In C/C++ you can wrap malloc() so that if it fails, you can start dumping cache until it succeeds. The solution is elegant, dare I say beautiful.
      In Java this is totally impossible.

      In Java there are things called weak references which you can use for this exact purpose. A weak reference is a pointer to a pointer, but the pointed-to object is considered available for garbage collection (as long as it isn't referred to anywhere else). This means you can do this:

      Object toBeCached = new Object();
      WeakReference wr = new WeakReference();
      wr.set(toBeCached);
      cache.put(cacheKey, wr);

      This, obviously, could be handled inside the cache for better encapuslation. But the point is that when garbage-collection runs, the items in the cache are fair game for collection. The obvious problem is that the GC will reap objects in random order, or it may even reap the most-recently-allocated objects first. But if that's a problem for you then you can probably make your cache smarter, such as keeping strong references to newer objects.

  25. You may see a diff in 1.5 by willCode4Beer.com · · Score: 2, Informative

    Sun is introducing shared memory in the new VM that should alleviate this somewhat.
    The idea is that the majority of the "fatness" comes from the libaries. If you only have to load the core libraries once, and each VM can use them then additional VMs won't add so much overhead.
    If this works, I'm wondering, will we get side-effects from the over-abuse of static member variables.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
  26. Re:Counter arguments by laffer1 · · Score: 2, Insightful

    C# and VB.NET are almost identical in features. What do you "sacrifice" that is really important? The .NET framework is still there. C# is just java like syntax for .NET. Its not 100% better as its billed by microsoft and consultants. I agree vb6 sucked.

    The java vm startup time is a problem for client apps, but server side its not a big deal. Running tomcat with servlets, jsp and the like is very fast. .NET app startup time is slower than running a program written in another language as well. Try running the ati control panel (.net version). Now that is slow. Limewire loads faster and its a java app.

  27. Re:Counter arguments by m50d · · Score: 2, Insightful
    In the end though, the MOST important thing is that these days, processor cycles are cheap.

    The typical home machine these days is still sub-ghz, and Java performs so poorly as to be unusable on such machines.

    --
    I am trolling
  28. Re:Whiskey Tango Foxtrot??? by parryFromIndia · · Score: 2, Interesting

    OP's comment is based on the fact that Java is usually deployed on those big iron Sun boxes (8-way minimum, 16-way, 32-way etc. with 32Gb RAM etc. - you get the picture.) Any darn thing runs reasonably fast on these machines. And when things execute in-memory and are JIT'ed there is no reason to believe Java code will execute slower than say C/C++ code. Plus lots of design patterns have grown to make up where Java performance sucks - Use huge thread pools to avoid creating threads on demand, cache as much as you can, pool objects to avoid doing new on big objects etc. Java/J2EE makes it possible to write robust server side applications quickly without having to deal with low level details. People pay a big price for this by having to buy those big boxes on the server side. It could be argued that smart C/C++ programmers can build something more reliable/scalable with less resources - but matter of the fact is that world is full of lazy "high-level" "abstract" "mediocre" programmers. Destop is a different matter altogether - people still have machines with mere 256Mb RAM with one pale CPU - C/C++ rocks there. Java sucks badly on the desktop - Graphics/Drawing is slow, startup time is horrible, simple apps can require boat load of memory and on top of this the UI looks nasty. Just a data point - Microsoft's VC# IDE requires 29Mb - it's written in C/C++ and embeds the C# VM. Netbeans and Eclipse - last I checked they needed atleast 100Mb!

  29. Maybe, there is a bit more to it, then just memory by dzafez · · Score: 3, Funny

    I haven't done anything with java in the last 5 years.
    *everybody.screem("w00t!");*

    I can understand the discussion about memory allocation is legitimate.
    *everybody.agree();*

    Now, saying this would not be the case anymore, so hence java is fast now, would be false.
    *everybody.status = iritated;*

    Writing jevecode does make yu handle a lot of errors...
    *everybody.ask("is this not good?");* ...BY HAND!! IT WILL NOT COMPILE ELSEWAY.
    *some.ask("is this not good?");*

    Maybe there is a loss of speed for handling all those errors as well.
    *FirstHalfOfCoders.grab(stone);*

    C coders don't check for every possible error.
    *SecondHalfOfCoders.grab(stone);*

    Maybe, sometimes, it is ok for a programmer, if from that code, there could
    be errors. While on the other side you buy speed with insecurity.
    *FirstHalfOfCoders.throw(stone);*
    *SecondHalfOfCoders.throw(stone);*
    *me.troll();*

    AND BY THE WAY; I LOVE THE "GOTO" STATEMENT!
    *me.run(away);*

  30. Good C++ programmers don't program C in C++ by Henry+V+.009 · · Score: 2, Informative
    A *good* C+ programmer will remember to deallocate all of his objects to prevent memory leaks. A *good* C++ programmer will copy his strings correctly to prevent buffer overflow exploits.
    No he won't. Because if he has to think about either of those things, he is programming C in a C++ environment. And is therefore not a *good* C++ programmer. His code is probably not even exception safe. He'd be kicked off any decent C++ programming team rather quickly. That aside, I'm reminded of a joke that does go somewhat against my point, but is still funny:

    Bjarne Stroustrup : why so many people use "C++" just as "C" ?
    Dennis Ritchie : because you named the language "C++", not "++C"
    1. Re:Good C++ programmers don't program C in C++ by swillden · · Score: 2, Informative

      I wasn't aware that C++ eliminated the issues with pointers and deallocation.

      With proper use of smart pointers, it does. Not completely, but very close.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  31. Performance is mostly about the design/code by JavaNPerl · · Score: 3, Interesting

    I have been doing Java programming for several years now and ported many C/C++ applications to Java, mostly server side apps and I'd say roughly 85% of the time the Java apps outperformed the originals, sometimes by an order of magnitude. Now these were more redesigns than straight ports and the performance gains were not because Java was any better from a performance standpoint, but because design is more of a factor in speed than the language used, especially for larger applications. Usually when I find big performance hurdles that are hard for me to overcome, I find I would have same issues in most languages, so finding a better design is usually the solution. If you are writing small - medium apps or mostly GUI apps then I might have reservations about Java, but for larger apps Java is a good choice.

  32. Re:Counter arguments by LarsWestergren · · Score: 4, Informative

    The typical home machine these days is still sub-ghz, and Java performs so poorly as to be unusable on such machines.

    A typical mobile phone is sub-ghz too, and there is plenty of J2ME software running on them...

    Java rocks on limited devices AND as server software. It is only on the desktop it isn't a big hit. Yet.

    --

    Being bitter is drinking poison and hoping someone else will die

  33. Cool code no longer means fast by jolshefsky · · Score: 2, Interesting

    I've never believed that Java's garbage collection is the root cause for its slowness. I do believe that Java's GC is the cause for its random (and more notably, its inconveniently timed) stutters.

    I think the more general Java slowness comes from the obfuscation of efficiency. In C for instance, ugly code correlated with inefficient code. This is no longer the case for object-oriented programming in general, and it is possibly worst correlated in Java.

    The example in the article provides a starting point for what I'm saying. It's based on the algorithm for a point in some Cartesian graphics system:

    public class Point {
    private int x, y;
    public Point(int x, int y) {
    this.x = x; this.y = y;
    }
    public Point(Point p) { this(p.x, p.y); }
    public int getX() { return x; }
    public int getY() { return y; }
    }

    public class Component {
    private Point location;
    public Point getLocation() { return new Point(location); }

    public double getDistanceFrom(Component other) {
    Point otherLocation = other.getLocation();
    int deltaX = otherLocation.getX() - location.getX();
    int deltaY = otherLocation.getY() - location.getY();
    return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
    }
    }

    The Component.getDistanceFrom() algorithm is considered "good OO style." By using bad style, though, you can break the pretty encapsulation -- and make "bad OO style" -- but get a performance gain:

    public double getDistanceFrom(Component other) {
    int deltaX = other.location.getX() - location.getX();
    int deltaY = other.location.getY() - location.getY();
    return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
    }
    }

    Both code blocks require the math (two subtracts, two multiplies, an add, and a square root) but the original block (unoptimized) also requires the allocation of the Point object and the two memory copies to store the (x,y) location.

    This is a trivial example, but my point is that in a complex Java project, readable and elegant code bears no correlation to fast and efficient code. I believe this is why Java is slow.

    --
    --- Jason Olshefsky

    Karma: Poser (mostly affected by adding this line long after everyone else did)

    1. Re:Cool code no longer means fast by patio11 · · Score: 2, Interesting
      You'll find that your two examples will compile to the same bytecode in any modern Java compiler. Trust me, after literally two months of trying every line-by-line optimization I could think of to squeeze every tenth of a percent out of the main loop I came to the conclusion that the guys at both Sun and IBM (jikes compiler) are just freakish code gods and that I should never, ever, ever attempt any optimization below the level of algorithm selection. How freakishly good was this compiler? I had an algorithm for solving N-Queens that could be implemented as either iterative or recursive. Obviously, in n-queens the recursive algorithm has a guaranteed maximum depth, so I would presumably gain a lot of speedup by going with iteration and avoiding the overhead with a billion function calls, right? Oh, wrong! I ran literally 10,000 trials and the difference was statistical noise, something like two hundredths of a percent in favor of the recursive algorithm (I know, WTF). Then I go digging for the answers why and a wise sage imparted on me the lesson I have just imparted on you -- Trust Your Compiler.


      (Oh, by the way -- other tricks they used to tell you in the early days of Java, like trying to make the getX() inlineable or breaking the standards they taught you in CS101 and replacing foo.getBar() with foo.bar, are also pretty much useless. The Compiler Knows All.)


      P.S. I eventually abandoned Java entirely for the tight-loop and rewrote that as a stand-alone C app, keeping Java for the networking and logic for the distributed application (which used, lets see, approximately 1/100000000000000000 of the amount of cycles as the actual computation loop did, that being mostly the point). C, unsuprisingly, beat Java by a factor of roughly 100 in terms of speed (a tight loop doing bit-level operations on integers, and I had the luxury of using GPLed code written by the guy who set the world record in this field as a base to start on, which meant the C, which both benefitted from hand human optimization and a much more mature compiler which was literally built to do this sort of thing, ate Java for lunch).

    2. Re:Cool code no longer means fast by nerdwarrior · · Score: 5, Insightful

      Except, you're wrong. You're assuming that the compiler is doing *no* optimization. So, how would a compiler treat the first "inefficient" code example? Let's take a look:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.getLocation();
      int deltaX = otherLocation.x - location.x;
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Look at the implementation of getLocation(). It's a simple non-recursive procedure. In virtually all compilers, a simple procedure like this is going to be inlined, producing:

      public double getDistanceFrom(Component other) {
      Point otherLocation = new Point(other.location) ;
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      (Note that to the compiler, all variables are effectively public, so this would not be an access violation.)

      Next, the compiler can (easily) prove (by inspection) that Point(Point) is a copying constructor. As a result, it can replace the use of new Point(other.location) with other.location so long as it proves it will not modify otherLocation, and of course, it can prove this quite easily by inspection of getDistanceFrom(). This results in:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.location ;
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Also, note that getX() and getY() are also simple non-recursive leaf procedures, so the compiler would have inlined them at the same time, so you would actually get code equivalent to this:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.location ;
      int deltaX = otherLocation.x - location.y;
      int deltaY = otherLocation.y - location.y;
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Which is now faster that your hand-written "optimization." Note in fact, that you "over-optimized" by replacing otherLocation with other.location twice. If a compiler were actually dumb enough to implement it that way, literally, it would have involved an extra (and needless) pointer dereference to get the value of other.location twice, when it already had it sitting in a register. (Fortunally, most any compiler nowadays would have caught your "optimization" and fixed it.)

      In fact, the compiler wouldn't stop here. It might even rearrange the order in which it fetches x and y to avoid cache pollution and misses. Do you consider that each time you fetch a variable? Most programmers don't, and shouldn't. The moral of the story is that most programmers fail to realize how smart compilers have become. Compiler writers design optimizations with "good coding practices" such as this in mind, and the programmer will be rewarded if he or she uses them.

  34. Programs by MoogMan · · Score: 4, Insightful

    Unfortunately, programs such as Azureus, which run piggishly slow on a 1.2GHz laptop do nothing to dispell these 'performance myths'.

    1. Re:Programs by Matt+Perry · · Score: 2, Informative

      It sounds like there is something wrong with your laptop. I have a 1.3 GHz desktop machine at home. I run Azereus and it's as fast as any other application.

      --
      Slashdot: Failed Car Analogies. Amateur Lawyering. Anecdote Battles.
    2. Re:Programs by matfud · · Score: 2, Insightful

      I would have to agree, especially on the firefox part. Leave it running for a couple of days, like I do when at work, and you will find it is using well over 1G of ram.

      Java has a huge problem with memory resources.It does not integrate well with the OS (ie it does not know when increasing its heap with cause frantic swappage). It does not work well on machines with small quantities of ram (unless you specify individual heap/gc parameters for all you java apps (which is well worth doing))

      However in server environments (and very low end devices) where you tend to only run one app at a time the performance is very good.

      Before you complain. I run IntelliJ idea, Tomcat, Ant (and a few other java apps) all at the same time (sometimes multiple copies of each) and have no problems. But the computer I run them on has 2 Gig of ram. With 1 Gig I was struggling a bit.

  35. What a bunch of FUD by SlayerDave · · Score: 3, Interesting
    From TFA:

    The common code path for new Object() in HotSpot 1.4.2 and later is approximately 10 machine instructions (data provided by Sun; see Resources), whereas the best performing malloc implementations in C require on average between 60 and 100 instructions per call (Detlefs, et. al.; see Resources).

    Wow, that's really shocking. Until you actually look at the Detlef paper and realize that it was published in 1994, 11 years ago!! Who knows, maybe things have improved a bit in 11 years. The author certainly thinks Java is getting better; maybe it's possible that C/C++ compilers have improved as well.

    1. Re:What a bunch of FUD by sjasja · · Score: 2, Interesting
      maybe it's possible that C/C++ compilers have improved as well.

      Unfortunately it seems nobody really has come up with radically better malloc/free in 11 years. Small tweaks probably yes.

      But if you benchmark your favorite C/C++ compiler (just run "free(malloc(16))" in a loop) you'll find that malloc/free indeed is of the order of 10 times slower than a similar loop in Java. There is no great conspiracy here; this is easy enough to verify yourself.

    2. Re:What a bunch of FUD by Sangui5 · · Score: 5, Informative

      Additionally, even if it takes more instructions per call, glibc malloc() will return freshly used "hot" memory to you, while the JVM will return the coldest memory to you--the author of the article admits that this is a problem, but it is worse than they say.

      First, you definately have an L1 cache miss. On a P4, that is a 28 cycle penalty. You also likely have an L2 cache miss. Fast DDR2 memory has an access latency of about 76 ns--call it 220 processor clock cycles. If you miss the D-TLB, then add another 57 cycles. Total cost of your "fast" allocator--305 cycles of memory access latency. 305 is somewhat higher than 100.

      Even worse, if you are on a system with a lesser amount of memory, you may miss main memory entirely, causing a page fault. That'll cost you several milliseconds waiting for the disk. That really really hurts, since 8 milliseconds latency from disk is twenty-four million cycles at 3 GHz. 24 million, 24,000,000, 2.4 * 10^6, no matter how you write it, that's a lot of cycles to allocate memory.

      All of a sudden, 100 instructions to hit hot memory seems cheap.

    3. Re:What a bunch of FUD by Sangui5 · · Score: 3, Informative

      The allocators in the current JVMs are smart enough to optimize for cache misses
      Allocation in any modern JVM is a pointer increment, nothing more

      So which is it? Smart enough to optimize for cache misses or just a pointer increment? You can't have both.

      The author of the article claims that, for 'new' objects, a modern VM uses a "stop-and-copy" style garbage collector with a few twists to cheapen the liveness detection (i.e. escape analysis). A disadvantage of such an allocator is that any new allocation to the heap will happen in some of the least-recently used memory. Also, every time you GC, you have to relocate all of your memory, forcing you to horribly pollute your cache, and turning all of your previously hot pages cold.

      unlike malloc() which returns whatever the OS deems ok at the moment.
      malloc() is a library call, not a system call. The OS is only involved if you need to extend the heap or if you've just allocated a very large object. So far as 'deems ok at the moment', the most recently used memory is what is generally returned (plus or minus size fitting to keep fragmentation under control). This maximizes locality, and minimizes your physical footprint. With a smaller resident set, more physical memory is available for things like other programs, disk buffers/caches, etc. which leads to even better performance.

      A simple allocator like described in the article may be "cheap" in terms of cycles, but it is very expensive in its side-effects.

  36. Just for you by MochaMan · · Score: 3, Informative

    Here's a link in case you ever get the urge to write some Java code.

  37. Re:Counter arguments by Midnight+Thunder · · Score: 2, Insightful

    Five minutes startup times is also a myth. Most small to medium size Java application I have start in under a minute. Of course the more dependencies and the larger the application the more time it will take. I suppose we could compare this to you average game, written in C/C++, which can take over two minutes before you are ready to go.

    For an enterprise application, running as a server, start-up time is not really an issue. What does matter is ho well it does once it is running.

    --
    Jumpstart the tartan drive.
  38. Real benefit of C++ is not performance... by ivec · · Score: 2
    Is this serious??
    Programmers agonize over whether to allocate on the stack or on the heap.

    I have never felt the last bit of anxiety when choosing to "allocate" an object on the stack. I do not even call this an allocation, I just use a local variable that happens to be an object.
    I only allocate an object on the heap when I know this object needs to be exported from the function -- which is something I'd better be aware of by design.
    Stack-allocation is an easy, default, way of life in C++. It is even a key idiom for managing non-memory resources (RAII).

    When programming in C or Java, what makes me agonize is to manually ensure that (non-memory) resources are released properly and in a timely fashin (files, locks, communication ports, etc). try...finally blocks, anyone ?
  39. Re:Counter arguments by sulam · · Score: 2, Informative

    While I'm sure you can point to a Java program which takes 5 minutes to start, these are the exception in the Java world, not the rule. In fact, the JVM takes seconds (a small number of seconds, less than 5) on all of my systems, including P3's as well as older AMD's. It takes less than 2s on my Athlon 4800+. I can go from Tomcat not running to it being completely started up and serving requests in 4s on my PC, and 11s on my older G5. My IDE, which is extremely feature-rich, takes ~90s to get to where I can start typing code from a completely cold start, in a middling (30K LOC) project. That includes a ton of lib caching and such, so that it can do incremental compilation in real time. It takes 16s to restart once that caching is done.

    As far as guzzling RAM goes, all programs these days guzzle RAM, and they're right to do so, because RAM is cheap. This is not unique to Java, the IDE I mentioned uses 56M once it's really going, surely not an unreasonable amount of memory for such a complex app. Java is still not the best choice for small scripts, Python would be better if your program is going to be mostly startup/shutdown time. C# is no better than Java though. Don't forget you need most of .Net in memory for your C# program, and that's no small chunk of RAM. The first time you start up a .Net app of any size you're going to be waiting for it to draw for just as long. And it's no better for scripts, just how fast does Mono start up anyway?

  40. Re:Counter arguments by Anonymous Coward · · Score: 2, Interesting

    A typical mobile phone is sub-ghz too, and there is plenty of J2ME software running on them...

    Java rocks on limited devices AND as server software. It is only on the desktop it isn't a big hit. Yet.


    Ha! That's a good one. I work with mobile phones, though I personally don't use J2ME. All the programmers I work with do though (the carrier chooses). J2ME really sucks.

    The J2ME spec has a lot of fuzzy places and "MAY"s. You will find the full spectrum of possibilities in such places. There are also many imlpementations that blatently fail to meet the spec. (I've heard that boolean operators *sometimes* short-circuit, but I'm not sure I believe that.)

    Fixed point math is common for these small systems. In Java, you end up looking like Lisp. FP.sqrt(FP.add(FP.mul(a,a),FP.mul(b,b))); Yuck. In C++, you look like C++. sqrt(a*a+b*b);

    Then there's the jar size limits. Some phones only give you 64k to work with. And on top of that, each new class and function adds to the size of your app. So if you want to do some nice modular OO design, forget it. With C++, no problem. There are no size limits (aside from usable memory) and extra classes/functions are nearly free. Again, in C++ you can reuse loops and wrapper code to shrink code size, passing in a function pointer for the inner part. In Java? The extra overhead for the class you'd need to work that way cancel out the benefit.

    Garbage collectors typically used in J2ME are way behind server and client versions. And when they don't work well enough automatically, system.gc() might force a garbage collection. Maybe, if you're lucky and the manufacturer felt like implementing it.

    J2ME phones are almost universally one notch slower than the BREW equivalent. Some of the Samsung phones have poor performance under BREW, but are simple dreadful with J2ME. It's the difference between getting 4-5 frames per second and getting 1-2 seconds per frame. And if you're doing funky stuff with bitmaps that the phone has a slow implementation for, in C++ you can walk around the implementation and do it yourself. In Java, you're screwed.

    J2ME is a joke.

  41. The problem with Java by Henry+V+.009 · · Score: 2, Insightful

    Garbage collection is nice. It does its job and it does that job well.

    But garbage collection only helps you manage one sort of resource. In C++, the RAII techniques that help you manage memory are good for every resource, from file handlers to database connections. Resource management in Java is not so nice. Often it is quite a hassle.

    Also, if you really want the benefit of garbage collection in C++, simply compile your program using something like the Boehm Garbage Collector.

    1. Re:The problem with Java by Henry+V+.009 · · Score: 2, Insightful

      Destructors throwing exceptions? In C++ one should never allow an exception to leave a destructor. (See Item 11 of "More Effective C++" by Scott Meyers for a good discussion of this.) If there is no way to avoid doing something in a destructor that can throw, you should use a catch statement to take care of things.

  42. Custom mallocs by Mybrid · · Score: 4, Insightful
    It is interesting that the benchmark was done against the standard malloc when I've found that most high performance systems software implement their own malloc and other systems code based upon workload characteristics.

    Which is the point.

    Systems programmers write systems code. There is no one size fits all. There is no silver bullet. Comparing out-of-the-box C/C++ to out-of-the-box Java is a non-starter in my opinion because I've never used out-of-the-box C/C++ for large scale performance applications. What Google did in writing custom systems software is something that cannot happen with Java and is the accepted practice for C/C++.

    Java programmers write applications in a "one-size-fits-all" performance environment. Comparing Java to C/C++ is like comparing apples to oranges.

    Serious C/C++ systems programmers write their own malloc and systems software.

  43. Re:Maybe you should look harder. by TheRaven64 · · Score: 2, Interesting

    Most memory leaks I have seen in C come from the simple fact that it is not possible to allocate space on the previous stack frame. If the runtime included a mechanism for moving an allocation to the caller's stack frame (which would be trivial to implement) then most of them would go away. One other work around for this which I have seen is to have separate call and data stacks. Rather than calling malloc, you call a function which gives you a block of RAM on the top of the data stack. The data stack can be pushed and popped independently of the call stack, so a function that needs to return an arbitrary amount of data simply allocates it on the data stack, and returns a pointer to it. The pointer remains valid until the next time the data stack is popped.

    --
    I am TheRaven on Soylent News
  44. Re:Counter arguments by marcovje · · Score: 2, Informative


    > Delphi is Windows only and owned by a company with a very questionable future (forget about Kylix). C# is > basically Windows only as well.

    The Borland implementation of Delphi is, but others aren't:

    http://lazarus.freepascal.org/

  45. Re:MOD THIS UP!!!!!! +9 FUNNY by wheany · · Score: 4, Funny

    Oh yeah! Now that you mention it, it really is funny! You see, the article talks about how Java is not as slow as is generally believed, but then the grandparent says that he posted the message using Java! That's not funny as such, but it is when you consider that it's supposedly the first post! And it's funny to think that he might have actually been the first to post the message, but since he was using Java, its slowness caused the message to be actually posted waaay late!

    Too funny!

  46. Re:Counter arguments by aaronl · · Score: 4, Insightful

    See, that right there is a huge chunk of the whole problem. If programmers weren't being lazy and arrogant jerks and assuming that nobody cares about how poorly designed and coded their algorithms are, or how blatently horrible their memory usage is, we would have a lot fewer problems.

    I don't care that Java will get there at some point, or that it's better now. I care about whether it actually works right, and right now it does not. It does have too long a startup, most of the UI toolkits are horribly slow, it does not follow native platform UI conventions, and it is just not as nice to use a Java app as it is an equally well written native app. It does take far too memory, especially compared to other languages. Even the cross-platform nature of the code is largely a lie. Different JREs don't support the same things, and many platforms lack a JRE. There are massive differences between the various editions of Java so as to make it useless to try to write something across them. Your Java app written against "Vendor X Version Y Edition Z JRE" should work fine on any other platform with the same version of "Vendor X Version Y Edition Z JRE". That's all you can safely say without a good amount more testing.

    However, most of all, my CPU time and RAM might be cheap, but they are abused every time I use an application written in that mindset. I have memory needlessly abused, and CPU time needlessly wasted every time I run some poorly coded program. That means that I lose time and productivity every time I run your poorly written app. That attitude pisses me off, why we should all squander our system resources so that a few lazy programmers can write some app a little faster and with less effort, rather than doing their job right.

    Programmer cycles are a lot cheaper than making thousands of people upgrade their hardware. I imagine those programmer cycles are a few orders of magnitude cheaper.

  47. Re:Counter arguments by DrXym · · Score: 2, Interesting
    C# or rather the CLR, is of comparable speed to Java. I use both day to day and don't perceive any difference between the two EXCEPT as far as UI performance goes. Windows.Forms is a lot faster than Swing, though probably no faster than SWT. This is due to it using native controls, and having no layout models to speak of. In fact Swing probably has no small part to play in the perceived speed of Java.

    Startup of Java seems a little slower than CLR but not markedly slower. Mono's startup is hardly a speed demon either. In all, I think most of the hype around the CLR is just that - hype. The CLR is a lot nicer virtual machine, and C# is as close to C++ / Java that I couldn't care which language I'm writing to, but the performance differences are IMHO neglible.

    As an example of how fast Java is, I have written a poker simulator which plays 1000 games from a deck of cards which is shuffled 1000 times for each game. The hands from each game are then sorted, and scored. It's very Vector and LinkedList intensive and each loop probably sees a dozen or so temporary Vectors or arrays used during comparison - i.e. 1,000,000 iterations with many more nested within. It takes just over a second on my 1.8 Ghz PC.

    As far as I'm concerned, that's plenty fast. I reckon I could probably halve the time if I bothered to replace all the vectors with fixed arrays.

    It would be hard to compare Delphi (as in traditional Delphi) to either C# or Java since it is a compiled language. I don't know what Borland are doing with it these days so I wouldn't be surprised if it's gone the CLR route too.

  48. Re:Not too bad by Swamii · · Score: 2

    No, it's not really fixed. It's just syntax candy that lets the developer see strongly typed primitives, even though in the underlying JVM, you'll notice that it's still just a list of boxed Objects, thus losing performance and memory benefits with the inducing of boxing and unboxing of each element in the list. Contrast this with the .NET or Mono runtimes, where the runtime actually creates code for storing primitive types, thus gaining a performance and memory benefit.

    --
    Tech, life, family, faith: Give me a visit
  49. Re:Counter arguments by Anonymous+Brave+Guy · · Score: 2, Interesting
    In all languages I know of, you get some library functions ready-made, and you need to code some stuff yourself.

    Most performance problems occur in the code you made yourself.

    Unless, like me, you're the guy who's writing that library that everyone else depends on, in which case the two are the same thing for practical purposes. In that case, trust me, you still use something like C or C++.

    Here are a few reasons why:

    • C(++) has value types. What TFA describes as if it's some sort of clever optimisation -- the detection of objects that can only be accessed within a single stack frame and can therefore be reduced to stack or register storage -- is the default in C(++).
    • Java uses "portable" floating point rules, which theoretically means 100% consistent results on all platforms (definitely a plus, unless you write naive floating point code like the example distance function in TFA and waste all the benefits anyway) but also unfortunately means that instructions often implemented as fast operations on a processor have to be effectively recoded by hand because those fast operations aren't precisely specified to match the Java spec.
    • No-one really uses malloc and free on a large scale in fast code. In fact, we strain to avoid using the C++ analogues, new and delete, and make extensive use of data structures and memory allocation algorithms we control ourselves to facilitate this. Java's performance is always going to be bounded relative to C++'s here, because I can always write an equivalent GC in the worst case, and usually I can do better. (There is a fair argument that most programmers will get this for free in Java, and will not invest the time and effort to produce equivalent code in C(++), but remember that I'm talking from the perspective of the guys who do, because we write the libraries everyone else uses.)

    Any of those in isolation is game, set and match against the arguments in the article. Put together, you get the same picture most of us have painted all along: Java's performance is adequate for non-critical tasks, but it's nowhere near the top of the pile when it really matters.

    BTW, in case anyone's wondering: yes, I do work on widely-used, performance-sensitive mathematical library for a living, and yes, as it happens I really have spent the last few weeks researching ways to increase the performance of that library even further.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  50. Real world results by man_of_mr_e · · Score: 2, Interesting

    While I agree that in theory, and in labratory conditions, Java is just as fast (sometimes faster) than C/C++, in practice it doesn't usually end up that way.

    The way normal people write code, and the libraries and functions that normal people use, java is slow as snot. I don't care why that is, it just is, and it makes me steer away from Java client applications if there is something that is native or .NET available instead.

    Real world results are different from labratory ones as far as Java is concerned in my book. And that's just my experience.

  51. So why are all websites running Java slow as hell? by nazzdeq · · Score: 2, Insightful

    As soon as you go to a website and seed the dreaded .jsp extension, you know you're in for a wait. All the websites that use Java are just ridiculously slow. Name one that isn't. Could you imagine Google running Java and some JVM?

  52. Article Summary and reality by radtea · · Score: 3, Insightful

    Summary: "If JVMs were smart, garbage collection would be fast."

    Reality: "JVMs are mostly very stupid, and you can never be sure what JVM your users are going to use, so in the real world of deployed applications garbage collection performance--and Java performance generally--is a nightmare."

    I am so tired of GC advocates talking smugly about theoretical scenarios. Who cares?. When I can run a Java app on an arbitrary JVM and not have it come to a grinding halt every once in a while as the garbage collector runs--or worse yet bring the machine to a grinding halt because the garbage collector never runs--only then will GC will be useful.

    The weasel-words in the article are worthy of a PHB: "the garbage collection approach tends to deal with memory management in large batches" Translation: "I wish GC dealt with memory management in large chunks, but it doesn't, so I can't in all honesty say it does, but I can imagine a theoretical scenario where it does, so I'll talk about that theoretical scenario that I wish was real instead of what is actually real."

    This is not to say that there aren't one or two decent JVMs out there that have decent GC performance. But having managed a large team that deployed a very powerful Java data analysis and visualization application, and having done work in the code myself, and having had to deal with user's real-world performance issues and having seen the incredible hoops my team had to go through to get decent performance, I can honestly say that up until last year, at least, Java was Not There with regard to GC and performance.

    The most telling proof: my team did such a good job and our app was so fast that many users didn't believe it was written in Java. It was users making that judgement, not developers. Users whose only exposure to Java was as users, and whose empirical observation of the language was that it resulted in extremely slow apps. They didn't observe that it was theoretically possible to write slow apps. They observed that it was really, really easy to write slow apps, in the same way it's really easy to write apps that fall over in C++, despite the fact that theoretically you can write C++ apps that never leak or crash due to developers screwing up memory.

    Every language has its strengths. Java is a good, robust language that is safe to put into the hands of junior developers to do things that would take a senior developer to do in C++. But its poor performance isn't a myth, nor is its tendency to hog system resources due to poor GC. Those are emprical facts, and this article introduces no actual data to demonstrate otherwise.

    --
    Blasphemy is a human right. Blasphemophobia kills.
  53. speed kills by planetfinder · · Score: 2, Insightful

    I believe that, directly or indirectly, an unjustifide emphasis on execution speed is the one of the biggest causes
    of the failure of software projects. The problems usually begin with the choice of
    implementation languages. Programming languages should
    be chosen for the ease and cost effectiveness with which they can be used accurately and reliably generate
    a correct and maintainable application that satisfies the customer.
    In my experience selecting a language because it is "faster" than another language
    before it is even known what the speed issue is for an application is just a costly mistake.

    For speed critical parts of an application an experienced C++ programmer might be a without-which.
    A tool like JWrapper can be used to connect a Java application to an optimized C++ library.
    Speed requirements should usually be dealt with towards
    the end of the development. Most of the execution time is usually spent in a small fraction of the code.
    Only that portion of the code should be optimized because optimizations can be costly to derive and implement,
    costly to maintain, and more difficult to verify.

    In the interest of peacefull coexistence we might all agree that:
    1. Java is sometimes too slow
    2. C and C++ programs sometimes have memory leaks.
    3. Writing efficient, reuseable, object oriented programs in C++ can be an extremely subtle business and,
    as a result, good and efficient C++ programmers are harder to find.

  54. Re:Counter arguments by masklinn · · Score: 2, Insightful
    As far as productivity, it depends what you're doing. Java UI's take longer to implement (that might not even be true for SWT interfaces) but the core language of Java is very fast to write code in.

    Nope, not compared to Python or Ruby (which yield codes rougly 5 times smaller in a quarter of the production time), not compared to Lisp for an ol'timer, not even compared to C# (by a quite small margin though, but C# has a lot of very nice feature Java doesn't have).

    Writing Java is faster than writing C/C++ indeed, but not "very fast", not without any referential to compare to, because dev-time wise Java gets it's ass handed to it by much more agile languages.

    --
    "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  55. How about some actual DATA? by happycorp · · Score: 2, Interesting
    We can go on all day saying Java is slower, no it isn't, but no one's opinion is likely to be swayed.

    A quick web search turns up several surveys with lots of benchmarks,

    http://java.sys-con.com/read/45250.htm
    http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html

  56. Java, It's not fat its big boned. by pauldy · · Score: 2, Interesting

    This is about as much of a myth as the myth of the earth traveling around the sun. There is a lot more to allocating memory than this article lets on. Psuedocode will always be slower than machine code no matter how you slice it. You can do various tricks to make it seem faster by instruction count at certain things but in the end those same things can be applied to compiled code like c/c++. Most people can accept that as fact and move on using Java where it seems appropriate. Make all the excuses and extraordinary claims you wan tint the end Java is just plain old FAT n slow, anyone in any programming course who has used java can tell you that.

    Oh and it is hard to test out his little theory on the free malloc in C++ because you can't do the same thing in Java. You can try but it will get around to the free part when it gets good and ready and may not attempt the malloc until you use the memory.

  57. Re:What does gc have to do with anything? by Mnemia · · Score: 2, Insightful

    I never said it was. I was just responding to the point that GC is unsuitable for hard realtime systems (which is false). It's simply another method of heap management, and can be implemented with realtime requirements in mind. I also never said that Java or any other current garbage-collected language is actually suitable for this. I'm just saying that there is nothing theoretically preventing these features from being used in realtime systems. Likely to do that we will want languages (or new features for existing languages) with more expressive means of specifying the realtime requirements in a high level way.

    (I do think that there are significant advantages to having a GOOD GC system that a lot of people ignore. They are simply another type of abstraction, which can be a gain when you have no need to worry about memory management implementation issues. Why should we reinvent the wheel over and over again when we can have the language designer develop a very sophisticated means of handling this automatically? There are times (such as in realtime situations) where you may want to get at the lower-level details, and that's fine. But in 90% of software written, this is absolutely unnecessary and leads to tons of bugs which could be avoided by using a higher level language.)

  58. Re:Counter arguments by Jonboy+X · · Score: 2, Interesting

    Ermm, one question: is your poker simulator multi-threaded? If not, try ArrayLists in place of your Vectors in the Java code. Vectors are internally synchronized, which will hit you for a pretty big performance penalty.

    Sorry, Vector over-use is one of my pet peeves. It's silly little programming goofs like this that make our programs slow, and give the anti-Java trolls more ammo.

    --

    "In a 32-bit world, you're a 2-bit user. You've got your own newsgroup, alt.total.loser." -Weird Al
  59. Java vs. PHP by Heembo · · Score: 2, Interesting

    I believe that this battle can be summed up in the battle of Java vs. PHP. Here we have a fully OO VM based language that has been widely deployed on both Unix and Solaris, vs. a (mostly) UNIX only scripting language turned web programming language with lots of web-specific features. I have developed large solutions in both languages, and it really comes down to: PHP rocks for quick-and-dirth websites. Put a PHP next to a Java guy to develop a basic ecommerce or content mgmt website, and PHP will TOAST that guy. Now required six-sigma reliability, 100+ hits per second, redundant servers w/ clustering, the ability to connect to multiple corporate database from different manufacturers, and other high-end enterprise features, and Java wins hands down. Not to mention of the security of PHP vs. the security of Java - PHP is "wide open" in many ways. USE a big hammer for a big nail, and a small hammer for a small nail. Java ran WebMD (many thousand hits per second, all data driven) with an early version of Java 1.1. - yes, we need to clean up the socket code some w/ SUN, but it worked, and it worked very well. The future looks to me .NET - Microsoft was brilliant - a well defined software app network architecture what is language agnostic. This time in a few years there will be many Java programmers writing web-service code behind the .net standard. Thanks for reading my stream-of-consciousness.

    --
    Horns are really just a broken halo.
  60. Re:Bragging about ignorance by gvc · · Score: 2, Informative
    I have not read the reference

    OK, I'll enlighten you. Well, not you, who stubbornly refuse to be enlightened, but somebody else who may be reading.

    With a stack or with copying GC, you do allocation by doing a simple add (or subtract) and a check for overflow. On many architectures the check can be implemented using dynamic address translation (virtual memory) capability of the hardware.

    With a stack you must pop the stack when you're done. Another simple arithmetic operation. With garbage collection, you do nothing at this time. Running score: stack 2 operations (push,pop); GC 1 operation (allocate).

    But with GC you eventuallly run out of space so you copy all the in-use storage. Here's a formula:

    in-use == allocated - freed .
    That is, the total number of pieces of in-use storage is strictly less (and in practice substantially less) that the number of allocations. Running score: stack 2 operations * #allocations; GC 1 operation * #allocations + 1 operation * (substantially less than #allocations).

    That is, for each allocation a stack regimen does a push and a pop, and GC does an allocation and some fraction (substantially less than 1) of a copy.

    While I'm at it I'll point out that there are many cases in which procedures may be implemented without using dynamic allocation - stack or GC-ed - at all . Your allusion to that mystical compiler that works some sort of stack magic "for free" is simply wrong.

  61. Re:Stack allocation is free and always faster by gvc · · Score: 2, Interesting

    I'll try one more time. There is no rule that says the compiler has to translate function calls and return into assembly-language (stack-based) calls and returns. There is a technique, known as continuation passing, in which returns are never used. You may educate yourself by acquiring Appel's book "Compiling with continuations" or by reading Guy Steele's master's thesis or, indeed, by reading the references already given.