8 ms·
Really? You've never heard people joke about Java being slow? Half the programmers I've met have this cult like hate of java and cite performance as the main re
by whois 9y ago
Really? You've never heard people joke about Java being slow? Half the programmers I've met have this cult like hate of java and cite performance as the main reason.
- timthelion 9y agoJava is slow, but not in this case. Tight loop java is fast. Anything that touches memory is slow. Anything that involves loading jar files is slow. Anything that involves starting the VM is slow. But tight loop java is fast, indeed, being a JIT, potentially faster than C (better branch prediction given that the JIT can optimize at runtime). So the claim that Java is slow is true. That's why so many people hate it. The fact that Java is fast is also true.
- tsmarsh 9y agoJava is slow compared to C/C++ and Fortran and comparable with SBCL / Rust. But it is fast compared to Python, JavaScript, PHP and Ruby. It's the rise of these languages that confuses me. They somehow got away with the 'fast enough' argument whilst Java is constantly being compared to languages that are designed for fine tuning for the target architecture. In my mind it is Java that is 'fast enough' and,with Java 8, very expressive. The continued success of these incredibly slow interpreted languages in enterprises where you need to buy servers feels like an anti-pattern.
- mjw1007 9y agoFrom my perspective, choosing Python over Java (on Linux) around 2001: It was easy to find benchmarks showing that Java was fast. But Java turned out to be slower in every situation we might consider using it. Command-line applications were slower because the JVM took ages to start. GUI applications were slower, apparently because Python would use C-implemented widgets while Java would do much of the drawing itself. Web applications were slower without any good excuse as far as I could see, but something in the application server that was the mainstream way of doing things added more per-request overhead than starting a whole new Python interpreter via CGI. CPU-intensive operations (I remember image resizing in particular) were slower because, again, you ended up comparing the JVM against a well-written C extension.
- jacques_chester 9y agoI would say that of these, most are still true-ish, except web apps and some CPU-intensive cases. Where you have a long-running service, Java shines. Java marketing was a disaster. Remember when it was going to be the replacement for browsers? It was not a great way to engender goodwill.
- jghn 9y agoI think that the part this is missing is that when comparing Java to Python/Ruby part of the argument for the latter is the dynamic language aspect. To the folks making these statements, Java is seen as involving all the headaches of those faster languages but none of the advantages whereas Python/Ruby have slower runtimes but come with potentially faster development time, etc. I personally don't like this comparison but it's how I see it made typically. Random anecdote which led me to stop calling Java slow: I'll never forget the time I took a 3000ish line Python program which had been heavily performance tuned and thus completely impenetrable. I converted it to a dumbest-scheme-possible naive implementation in Java weighing in at roughly 100 lines , expecting that to be a first pass. It turned out that the Java implementation was many times faster so we called it good enough and moved on with life. Obviously YMMV and all of that
- aw3c2 9y agoI just looked at the list for where my beloved cherrypy might sit. It is almost at the bottom. But that does not matter because writing webapps with it is easy and fun.
- tsmarsh 9y agoAs I see it, most sites don't need the hardware they're allocated. If you want to sleep on the weekend, you need at least two and probably three servers. That is almost certainly in the realms of 10x what most applications actually need. So a language that is 10x slower than C isn't a big deal. CherryPy fits nicely into this window of opportunity, but as soon as you have to go back to your boss and say "I think we need a bigger boat" someone should be asking questions about library and language choices, at the very least there should be a conversation about prototypes vs production architectures. Similarly, Python and the dynamic languages are 'fast enough' because in the 90s the bottleneck was IO, not CPU. That is still true, but is becoming less true. SSDs rapidly closed that gap, and it looks like memristor storage could mean that non-volatile RAM is as large as SSD and as fast as DRAM is today. The dynamic language decision to focus on single threaded performance is also smart, but that will stop being true when CPU have hundreds of cores, instead of 10s. Synchronized access to cache is 100x slower than regular access. So to see benefit for work loads other than the "embarrassingly parallel" with multi-core you need around 100 threads. The new competition in the CPU market might see the first 100 core die on the market in 5 years. The trend towards 'serverless' could be even worse for dynamic/interpreted languages. Smaller slices of billing will show that the same service written in Java vs Python cost 5-10x less. That was harder to show when you had to pay for at least two servers for every deployed service, now it will be very clear to CFOs how much language choice affects their bottom line. What this means is that the perceived difference in performance between Java and Python can only grow over the next 5-10 years. If Java continues to gross you out, I'd be looking to pad your resume with something like Clojure / Go / Rust. High productivity, high performance languages are here and their relevance is growing.
- fh973 9y agoDo multi-threaded workloads, which a lot of high performance workloads are, Java has also the potential to be faster than C++ due to garbage collection and threading aware optimizations it can make. Memory allocation, especially when memory lifecycle spans threads can be expensive in C++. "A JVM does that???" by Cliff Click is a good introduction on what can go in the background.
- jackmott 9y agoso write a specialized GC for the task in C or C++. C++ can always win! JVM has hotspot? use profile guided optmization in C! There is no escape!
- sgift 9y agoIf you are one of the three people in the world that can do it. ;-)
- fauigerzigerk 9y agoJust use an arena allocator (or similar) where appropriate. It's not difficult and it's how C, C++ and Rust win all micro benchmarks that involve memory allocation: http://benchmarksgame.alioth.debian.org/u64q/binarytrees.html http://benchmarksgame.alioth.debian.org/u64q/binarytrees.htm...
- mohaine 9y agoTo be more fair, java is mostly slow on startup which which is mostly due to: 1) Swing. I have no idea what this does on startup but it is bad. This is what killed most java GUI apps. A simple AWT or SWT app will pop open while a simple swing app will take a few seconds to get started 2) Jars on systems with virus scanners. Jars are just zip files. Many virus scanners will unzip and scan a zip on every open which leads to each jar being unziped at least 2 times and often more if the app has to load more things from the jar at a later time. 3) Spring. Really spring is just a bad idea all the way through and most of the reason people hate java is Spring. Huge XML configuration files instead of code? Spring (mostly annotations now). Stupid names like AbstractSingletonProxyFactoryBean? Spring. That aside, on startup Spring will auto generate classes which really slows things down. This could have been done during the last build but spring does it at each startup which is really slow. Spring Boot has helped with startup times but it is still slower. After startup Spring continues to kill performance. The underling code is full of maps to control request lifecycle so instead of just calling a method it has to ask "who all is configured to do something at step PreParseRequestEncoding?" then again at ParseRequestEncoding, PostParseRequestEncoding, PrePareRequestBody, ParseRequestBody.... Not real names but the idea and number of steps is. Most of the time the answer is "nobody" but it has to ask for every step that might ever need something done. Add on top of this JPA which is super easy but quickly breaks down to a lot of DB calls. JPA is great for people who don't want to learn SQL and simple CRUD apps but anything with any amount of data will quickly slow down to thousands of DB round trips.
- karmakaze 9y ago> JPA I'd like to see some reallife-ish comparisons with Jooq
- nova22033 9y ago>JPA is great for people who don't want to learn SQL That's like saying Java is for people who don't want to learn C...or C is for people who don't want to learn assembly. It's the right tool for the right job. If you use it for everything, it's no so good.
- jacques_chester 9y ago
- JepZ 9y agoActually, Java was very slow 15 years ago and that might be the reason for that cult.
- rsynnott 9y agoI think it’s possibly an age thing. Java really _was_ pretty slow in the mid 90s, and the reputation has never quite gone away for people exposed to it then. People only exposed in, say, the mid-noughties have less reason to ever get that impression, though.
- mikeash 9y agoDecades ago, when Java was new, the VMs were not very good, and the comparison was with C and C++, it was commonly said that Java was slow. But these days, Java VMs are vastly better and Java is competing with languages like Python and Ruby. The way things are today, the assumption is that Java is faster than its competition.