Why Is Java So Slow

Posted on -
Why Is Java So Slow 3,6/5 9321 votes

Nov 20, 2007 Hi all, I'm wondering if anyone can help me understand why my Java is being very slow compared to an equivalent program written in 'C'. I see many cases when Java is terribly slow for simple. Why Java is a factor 2-3 slower than equivalent C++ program? So its C for speed. Java for production.

  1. Why Is Java So Slow
  2. Why Is Java So Slow In Windows 10

For a long time in SO and in other places Java has the reputation of being slow. From to in questions and answers, people still believe Java is slow based solely on experience with it in the 90s. This is my issue: we have (most) of the reasons that people believe Java is slow. Outside of small things, Java is pretty fast. So why is it that people still refuse to believe Java is fast now? Is it part of their mindset that anything thats not C/C is slow?

Is it because people don't check over time? Is it because people are just biased? It's the applications.

As you note, we have proved, time and time again, that in contrived scenarios Java code can meet or even beat the performance of so-called 'performant' languages like C, C, Lisp, VB6, or JavaScript. And when presented with such evidence, most sane, open-minded opponents will hang their heads in shame and promise never again to spread such slander.but then, they fire up Eclipse, or NetBeans, or Guiffy, or enable the Java support in their browser, or try to run an app on their favorite feature phone. And they wait for it to become responsive.and wait.and wait.and wait.and wait.and.what did I promise never to do again? Sorry, must have dozed off. This question operates on false premises: where it counts, Java is still slow. Where it counts are computation-heavy algorithms on large data sets.

Granted, these can be optimized, sometimes to be on par with C/C code, but only at the cost of modularity and genericity. Efficient C code can be designed to be generic and usable as a general-purpose library.

Java code can’t. Just look at the heavily optimized Array.sort method, which uses different implementations for all fundamental types, and whose object variant is still much slower than C’ generic sort because these objects have to dispatch equality comparisons dynamically. Granted, just in time optimizations as performed by the HotSpot engine can actually predict the target of these virtual calls and attempt inlining. But this is still slower than the directly inlined call that is dispatched inside C’ sort method.

A former colleague of mine has done comparative benchmarks of a problem on huge data sets ( q-gram counting using dynamic shapes) with a templated C implementation and an object-oriented Java implementation. The Java code was orders of magnitude slower than the C code.

Of course this is comparing apples with oranges. But the point is that the Java implementation was the best possible implementation (in terms of performance, given the degree of modularity required for a library), and so was the C implementation. Unfortunately, the benchmark data is not freely available but others have found similar numbers when comparing the overhead of runtime abstraction. For instance, Scott Meyers writes in Effective STL about the overhead of C’s generic qsort function: C’s sort virtually always embarrasses C’s qsort when it comes to speed. At runtime, sort makes inline calls to its comparison function while qsort calls its comparison function through a pointer. In my tests on a vector of a million doubles, sort ran up to 670% faster. I'd say it's because when people first encountered it, it was slow.

Based on that, they formed an impression of it. That impression is unlikely to change if they don't use it, and they don't use it because of that impression - it's a vicious cycle. I must admit, I had the impression that Java was slow, and yes, that was from my previous exposure to it. I've now moved on to different languages and have had extremely limited exposure to Java since then. Consequently, my opinion hasn't changed much. It has nothing to do with how fast Java becomes.

In people's minds Java is a const identifier associated with the word 'slow'. There's little, nothing you or Oracle can do about it.

Just be happy that Oracle hasn't destroyed the Java programming culture (yet) by doing anything. Like charging excessive licensing costs to use it. Or suing people based on software patents previously owned by Sun.::sigh:: I hate to be the naysayer here but, unless Oracle and Google settle the Java struggle on nice terms, or Google is forced to purchase Java and makes it a 'proper' open source platform, Java is well on it's way to being the kid on the playground that has lice.

IE, no one will want to touch it with a 20ft pole. Note: Just to be clear, when I say generation I'm talking in people terms not computer terms. IE, until the people who hold that perception die of old age or replaced by a younger generation the perception will hold true. Think in terms of 5 decades not 5 years. @Reallyethical Not in the mainstream. How many businesses depend on Lisp, Fortran, Cobol.

With lisp, it's mostly trapped in academia and used as a model for features of other languages, few use it for actual production projects. Fortran has become a niche language for high performance mathematical modeling and Cobol only remains because the banking industry is to damn scared to change their old/dependable code to a new platform. C is the glaring exception because it is still very widely used and adopted today. – Nov 11 '10 at 0:24. One reason is that people trust what others say instead of what they see.

Why Is Java So Slow

According what I was told when I first started programming, Java is 'slower' than C, and reason why Java could be used is because it's 'convenient and easier'. It's very commonly believed that Java brings Safety and convenience, at the cost of performance. Even when later C# is invented people believe it's faster than Java because it's 'native'. But the truth people see without sensing it, is that, eclipse, the IDE that's built with Java, is absolutely the FASTEST IDE in class. I've used nearly all main stream IDEs, those from MS and GNU, Borland., eclipse is the absolute king, of IDEs, largely because of it's fast. Another reason is its long start up time.

Java is not suitable for developing a tiny app that stay in system tray, consumes a little memory, popup a dialog reminding you to take a break; or a notepad that you use to open a text file, read it and close it. It should be used on something BIG, like a web server that's always there, make optimized use of you computing resource, respond to millions of requests every hour. Or an IDE like eclipse that manage thousands of workspace files. You don't know you Java app is fast until it has run for at least several hours, I believe. @bigown 'Why do people still say Java is slow?' Because they are dumb. Because they have no work experience, but think they are the living incarnation of Dikjstra or the second coming of Linus Torvald, oh I dunno.

Java

Why Is Java So Slow In Windows 10

The reasons for saying such a retarded thing are so many, but usually stupidity, mindless subjective fanboyism, and emotional attention-whoring seem to be behind them. Let's disect this so that you can see the truth of what I've just said above: First, what is slow, in what context, for what, under what conditions, with what engineering/scientific/business purpose (for saying tehe it sucks is not one of them.) Any person who says 'X is slow' for any technology X, or simply 'X is Y' where Y is some type of negative statement, without answering any of the questions above should be dismissed as a fool. Statements like that don't have a place in engineering.

Windows

In politics and juvenile chat rooms maybe, but not on engineering. Second, most of these misguided fools cry about Java being slow because ZOMG, their eclipse takes forever to fire up (gee, load the thing with all the plug ins, and guess what happens.) Most of these fools don't even know how to tune the jvm for eclipse to operate fast (or for any Java application for that matter). That is, they have no clue about performance tuning, which is a reality not just for Java, but for any non-trivial system, be it hardware or software. So right there, they disarm themselves for any technical validity in making such mindless statements. Third, let's consider what the bulk of Java development is for: back end OLTP first and foremost; monitoring systems coming second. Either type of system is intended to run in clusters, and to run uninterrupted for weeks if not months. Does it really matter then that your little eclipse or toy app takes a minute or two to load when the purpose of REAL Java apps is to run for extended periods of time?

Context, people, context. Lastly, the backbone of OLTP on Google and Ebay run on Java. I would take that as a proof by contradiction that Java is not slow (at least for conditions that matter, not for little toy experiments, benchmarks and unverifiable annecdotal evidence done specifically for the purpose of saying 'tehe X is slow, it sucks.' There is engineering, and there is fanboyism.

Guess which category statements like those belong to? @David - Obvious statement.

Anyone knows that Java is slower than C. That does not logically follow that it is slow, however. Neither mentioning of gcc flags give the comment validity.

It only states that it is slower than something else. A jaguar is slower than a cheetah. Does that make the former slow? Try some engineering objectivity and ask yourself this: can one logically declare, arbitrarily, that something is slow simply because it is slower than something else without mentioning a context of operations that defines what is fast enough and for what? Can you, logically? – Oct 22 '10 at 19:46.

@luis espinal You sound like Kant:) People here have made an implicit assumption that slow means slower in comparison to other practical, production-ready languages like C. (Remember physics??) when you measure potential energy, you always measure it relative to some ground. Now going by your grammar, 'X is dumb' is baseless. And 'X is dumber than Knuth' does not make X an absolute dumb, as pretty much anyone can be X here. I agree calling a lang slow is not elite, but the people here who say that are not 'dumb', but just happen to have made an agreed upon implicit assumption.

– Oct 5 '11 at 13:37.

Slow

Attention, Internet Explorer User Announcement: Oracle Community has discontinued support for Internet Explorer 7 and below. In order to provide the best platform for continued innovation, Oracle Community no longer supports Internet Explorer 7. Oracle Community will not function with this version of Internet Explorer. Please consider upgrading to a more recent version of Internet Explorer, or trying another browser such as Firefox, Safari, or Google Chrome. (Please remember to honor your company's IT policies before installing new software!).