Addressing the "Java is Slow" Myth

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

91 Replies - 6816 Views - Last Post: 11 June 2009 - 08:47 PM

#1 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Addressing the "Java is Slow" Myth

Post icon  Posted 02 June 2009 - 12:54 PM

It's been what...14 years since Java was released? That's quite a while and yet people still believe myths about Java that haven't been true for at least 10 of those years. Despite the improvements in JIT compilers, hotspot JVMs, garbage collection, and concurrent programing people still want to believe the negative disinformation propogated by people who are tragically misinformed, yet somehow manage to speak as though they are authorities on the subject. the next time someone tells you Java is lower than XYZ, ask them how they came to that conclusion and to what benchmarks they are referring. You'll likely not get an answer that is more than hearsay or anecdotal evidence. Do you honestly think Google (the company whose reputation was built on the speed and efficiency of its search algorithms) would be such a huge advocate and client of Java if it were really slow? Yet, I still hear people say things like, "Well, you can use Java for the desktop, but if you get into embeded systems where space is tight or performance-intensive apps you need to use C/C++." Last time I checked, Android doesn't support C++. Look, we alll know that every language, at some point, gets compiled to native code. But that doesn't mean that more layers of abstraction will always mean less performance. I've read recently (although I can't find the reference) that Java outperforms C in many areas. I believe that's probably true. Unfortunately, many of the benchmarks you can find are done by people who don't understand how the JVM and/or JIT compiler work because they don't allow enough time for either to do their work. Of course Java will perform slower than expected if you continuously stop and start the JVM. Do I really need to explain why? I hope not.

Food for though:

Here's an article interviewing two Google Engineers about Java performance. These guys did a presentation at the Software Development West conference last year. I can't find their actual talk, but here are the powerpoint slides.

Here's an interesting page. full of infor about various recent Java versions and other myths/legends. Be sure to check the Java Legends link at the bottom.

Here's an article from 2005 written by Brian Goetz (Author/Concurency guru). The info is obviously a bit old, but it's difficult to find recent articles on the subject. This is probably due to the fact that most professionals who use Java consider it pretty obvious that it's not slow.
Java theory and practice: Urban performance legends, revisited

This post has been edited by Core: 04 June 2009 - 09:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Addressing the "Java is Slow" Myth

#2 c0mrade  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 412
  • Joined: 16-November 07

Re: Addressing the "Java is Slow" Myth

Posted 02 June 2009 - 05:49 PM

Can't say that enough... good write up. Should have posted it in the C/C++ forum though ;).

Although, I'm pretty sure Google's search engine is done in C++... so maybe that wasn't the best analogy.
Was This Post Helpful? 0
  • +
  • -

#3 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Addressing the "Java is Slow" Myth

Posted 03 June 2009 - 07:23 AM

Indeed, it’s not an analogy at all. It is an apt example though, in that it helped me to make the point that Google got its reputation by having the fastest and “best” search engine and therefore probably esteems speed/efficiency. The fact that they used C++ (assuming you're correct) has no bearing on the discussion since it’s Java, not C++, that is the subject of this article. But those algorithms were written years ago when Java's (version 1.2) speed was lagging behind that of native code. So, who's to say which they would choose now that Java’s speed is comparable/faster to native code in many areas? I think Google chooses the best tool for the job. I don’t personally care what that is, but the fact that they choose Java for an increasing number of things and the fact that many of their developers advocate using Java, tends to contradict the myth that it’s slow, hence my point. Although I use the term “C++” once or twice, this is not a “Java vs. C++” article.
Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Addressing the "Java is Slow" Myth

Posted 03 June 2009 - 10:26 AM

View PostProgrammist, on 2 Jun, 2009 - 01:54 PM, said:

Addressing the "Java is Slow" Myth


THANK YOU. :^: :)
Was This Post Helpful? 0
  • +
  • -

#5 phil1000  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 176
  • Joined: 26-February 09

Re: Addressing the "Java is Slow" Myth

Posted 03 June 2009 - 10:41 AM

I thought Google used quite a bit of Python? I could be wrong though.
Was This Post Helpful? 0
  • +
  • -

#6 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Addressing the "Java is Slow" Myth

Posted 03 June 2009 - 10:54 AM

Although I agree with you that Java's slowness is exaggerated, you can't deny that no matter how much Java improves, it can never beat the overall speed of a compiler that produces native code.

Read this for more information on speed of programming languages. (Note that although Java is extremely fast, it loses out on larger code sizes)
Was This Post Helpful? 0
  • +
  • -

#7 c0mrade  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 412
  • Joined: 16-November 07

Re: Addressing the "Java is Slow" Myth

Posted 03 June 2009 - 12:38 PM

Quote

Indeed, it’s not an analogy at all.

Haha, yeah, that's what I get for late-night posting...


SO - to be a little more clear in the point I wanted to get across: Slow is subjective.

As you stated, Java is not slow anymore, and people who have never tried Java because of it's speed are clearly mistaken.

However, Java will never be faster in general than native code (for obvious reasons). The point I think you were trying to make was that the performance penalty when using Java is almost always negligible - but you didn't seem to communicate that in your post.

This is why I say that Google is probably not the best example. Although they do use a lot of Java, their main function is in C++, presumably for performance reasons because when you serve as many requests per day as they do little things matter (look at there html, not one unnecessary space).
Was This Post Helpful? 0
  • +
  • -

#8 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Addressing the "Java is Slow" Myth

Posted 04 June 2009 - 10:54 AM

@born2code: Although I don't think Java is the fastest language for every application, I wouldn't say "never" at this point.

@c0mrade: That's not really the main point I was trying to convey, but it was certainly a strong implication. For the main ideas, you need look no further than my title and first few sentences. If I were trying to make the point you mentioned I would have focused in on that and used lots of data to attempt to prove it. But I was rather hoping that those who read my post would also read the articles (or even Goole more) and come to a conclusion on their own.

I hear what you are saying, but I think your perception of my use of Google as a bad example points to the fact that you're still missing my message. It's not about the fact that Google uses C++ (or any language) over Java in a particular instance. It's the fact that a company which (I believe) respects efficiency and speed is using Java heavily. It doesn't matter if they are using C++ for their search functionality because I never said Java was the "fastest" language in all domains. I also made the point that the search algorithms were implemented when Java was in its infancy, so it doesn't really prove anything about C++ and present-day Java.

To anyone else who's got their hackles up: This is NOT a "Java vs. <other language>" post. This is not a "Java is the fastest language post. Please read the title. I'm addressing old misconceptions about the efficiency of the JVM that seem to linger on for some reason.

This post has been edited by Programmist: 04 June 2009 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

#9 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 783
  • View blog
  • Posts: 7,610
  • Joined: 05-May 05

Re: Addressing the "Java is Slow" Myth

Posted 04 June 2009 - 11:02 AM

JAVA itself runs just fine for things you need it for. However it's obviously slower than C, which in turn is slower than hand coding ASM. Or any other language that's pretty low and compiles. The thing that irks me is the JAVA fanboys who say it runs just as good or sometimes faster than C. I think a much better statement is JAVA is fast enough for most practical applications because JAVA itself isn't slow.

JAVA itself is still not known for it's speed. But it isn't going to matter if you suck at programming and write a cubic or even quartic N nightmare when something much simpler would have sufficed- it's going to run slow in any language. Still, I use JAVA too because of how easy it is to write a custom server for something you want. Especially a game server. I'll never use it for something a customer or end user will get, but it sure does it's job well at the things it excels at.
Was This Post Helpful? 0
  • +
  • -

#10 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2648
  • View blog
  • Posts: 15,668
  • Joined: 24-September 08

Re: Addressing the "Java is Slow" Myth

Posted 04 June 2009 - 01:03 PM

I've hear a lot of rag on Java, not just because it's slow, but because people claim that it can't do as much stuff as C++. Is that even true? I mean, when I talk to people and they ask "Oh, what language do you program in? Java?! Ewwwww." Why? <<<((actually Danny's really bad about that))

This post has been edited by NeoTifa: 04 June 2009 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#11 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Addressing the "Java is Slow" Myth

Posted 04 June 2009 - 01:22 PM

Java can't do as much memory-wise as C++, but that makes sense. Other than that, I consider C++ to be less valuable than Java. Granted, I don't do things in C++ if I can avoid it, so I have less experience with it, so I might be a bit biased.

*Flame-retardant suit for the "less valuable" statement*

Danny is REALLY bad about hating Java. It's probably the fact that it's easy and he looks for a challenge.
Was This Post Helpful? 0
  • +
  • -

#12 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Addressing the "Java is Slow" Myth

Posted 06 June 2009 - 04:55 PM

I had to do a huge academic report comparing the speed of java to c++ across a whole range of benchmarks. It was quite interesting though that I could not find any recent attempts and reports at comparing the speed of languages, which is why everyone still believes java is slow (they are just reading old reports). When I performed these benchmarks, I was quite surprised. Java actually outperformed C++ in nearly every test, besides trigometric functions, to which it was disgracfull!!!
Was This Post Helpful? 0
  • +
  • -

#13 KeyboardKowboy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 142
  • Joined: 15-December 08

Re: Addressing the "Java is Slow" Myth

Posted 06 June 2009 - 06:49 PM

Interesting topic Programmist... it's an argument I constantly have with a co-worker. He's a C++, C#, .NET fanatic. As I am also a fan of these platforms, I will always cherish Java for certain scenarios. Doesn't all .NET code run through a JIT (Just-In-Time) compiler, the Common Language Runtime (CLR), which acts as an interpretor as well? As is just fact, Java is interpreted... it will never be faster than native code. However, I always argue that the performance hit, especially with the current JVM and system hardware, is negligible. Am I correct though that all .NET languages are also interpreted (sort of)?

This is going off topic, but it popped into my head and wanted to see what you thought. The other point he likes to make is that Java source code can be easily decompiled (Security Issue). I know other language platforms can be decompiled as well (.NET). Is it just that Java has no built in obfuscater (Like .NET)? (Or does it and I've been in the dark for way too long?!) :blink:
Was This Post Helpful? 0
  • +
  • -

#14 Dantheman  Icon User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • Posts: 445
  • Joined: 27-May 09

Re: Addressing the "Java is Slow" Myth

Posted 06 June 2009 - 07:14 PM

Is it a myth? Well, it depends. After all, fast and slow are relative terms. For some applications Java's speed is not a concern, but for some it is. In the later case, it's not a myth, it's a fact.

The fact is, Java is slower than C/C++. Yes, JITs have significantly reduced the gap, but they didn't eliminate it. In addition, Java uses a significant run-time overhead that will always be there.

1. Every object is created on the heap.
2. Garbage collection.
3. Increased memory usage and run-time checking (all objects have a virtual table, arrays checking for correct index, etc..)

I'm sure there are more examples, but that's all I can think of at the moment. The point is, Java will never be as fast as C\C++. Does that make Java slow? Yes, sometimes it does. Sometimes it does not. It all depends on the context.

P.S. I've read your question again. It seems you don't differentiate between Java being slow and it beeing slower. Is Java slow? Again, it depends on the context. Is Java slower? Of course it is!!! Heck, we don't need a Ph.D. in computation theory to understand that performing more operations, taking up more memory, and running additional run-time checking, results in slower code.

Quote

the next time someone tells you Java is lower than XYZ, ask them how they came to that conclusion and to what benchmarks they are referring.


No need for benchmarks. It's a common sense.

Quote

Do you honestly think Google (the company whose reputation was built on the speed and efficiency of its search algorithms) would be such a huge advocate and client of Java if it were really slow?


Sure. Why not? Or are you saying that the only thing that determines language's usefulness is it's speed? As shocking as it may sound, not everything in computer science is about writing super-fast applications,

Quote

Last time I checked, Android doesn't support C++


Yep. Not everything is about super-fast programs. Shocking.

This post has been edited by Dantheman: 06 June 2009 - 07:31 PM

Was This Post Helpful? 0
  • +
  • -

#15 Darkhack  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 208
  • Joined: 25-November 08

Re: Addressing the "Java is Slow" Myth

Posted 06 June 2009 - 10:51 PM

Awesome source: http://shootout.alioth.debian.org/
Java vs C: http://shootout.alio...n...2=gcc&box=1

In terms of CPU speed. Java is about 1.5x slower than compile code. Not bad at all. JIT tends to be quite good these days. In fact, even though I'm a hardcore C advocate, I'd rather use a JITed language for web development because having the cached bytecode run by a VM is probably faster than spawning/terminating a new process for each connection.

My criticism has to do more with the memory usage. Java uses about 15x more memory. Now what do I get in return for that memory investment? Garbage collection. That's not very compelling at all. The whole point of garbage collection is so that I don't leak memory, but I actually end up using more memory because of it. That just seems so backwards to me. The second argument may have to do with programmer's convenience. Okay fine, the garbage collector doesn't save me from sucking up memory but at least it will save me from segmentation faults. But are segfaults truly that much of a problem? If you know how to manage memory, then no. When I first started programming in C, I'd get segfaults as often as I got boners in sixth grade and making them go away was just as difficult (though not as fun) and they'd keep popping back up. However, now that I have more practice and know what to look for, it isn't much of an issue. I think it's that initial awkward phase that puts most people off about C and sends them running to the hills for languages like Java where segfaults don't occur. Once you are more skilled though, it's almost a non-issue. Plus, you can always fall back on Valgrind or the Boehm garbage collector if you'd like.

I've never heard a skilled programmer say that a garbage collector has saved them any significant amount of time. It's a nicety, but a lack of it wouldn't slow you down too much. In fact, it forces you to be more careful and can perhaps help you find other bugs in your code. Usually when my program segfaulted, I was also doing something else wrong in the code too. Another example of this is the GNote project which aims to make a C++ version of Tomboy (C# with Mono). The GNote developer was very quickly able to catch up. In fact, not only was he able to catch up in just a couple of months, Fedora will be switching from Tomboy to GNote for version 12. If memory-safe languages were really that much better, one would have predicted the process to take far longer. Programmers who need a garbage collector need it because they are producing garbage. The benchmarks of GNote speak for themselves. And if you're using C++ and keeping all your dynamic memory inside of classes with the proper constructors and destructors, you almost forget you're not using a memory-safe language. When was the last time you had a segfault while working with the built in string class?
Was This Post Helpful? 1
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »