News for hackers. Stuff that matters.
Re:Java vs. Go performance by hanief on Friday April 24, 2015 @02:49AM (#9431767)
Interesting. All this time I have a perception that Java app is slow as hell. What a terribly wrong assumption. Color me impressed.
Re:Java vs. Go performance by CookWithMe on Friday April 24, 2015 @03:22AM (#9431859)
Well, a lot of Java web apps ARE slow as hell, but one can't really blame Java-the-language (or the JVM) for it.

Two examples from my experience:

JSF is doing lots of "magic" trying to keep state. It isn't exactly quick to render a simple hello world page, but if you mess up the state on a somewhat complex page, JSF spends ages in it's six (yes, six!) lifecycle stages [0].

Hibernate is probably the worst offender. Well, the interface is somewhat nice: you don't have to care about loading objects from the database, Hibernate will load them for you. One object, one request at a time. Looking at the hundreds of generated SQL requests it's quite easy to figure out how you would write better SQL... but you don't write the SQL, Hibernate does :)

The lesson IMO is: If you're writing everything from scratch, language performance is important. If you're using frameworks, the performance of the whole stack is way more important and one should probably compare benchmarks - or even real-world applications that are similar to ones use case - of the whole stack.

[0] http://docs.oracle.com/javaee/5/tutorial/doc/bnaqq.html

Re:Java vs. Go performance by vetler on Friday April 24, 2015 @03:40AM (#9431909)
Well, to be fair, Hibernate is just a tool - and as many tools, it can be used the wrong way and the right way. Most people seem to not spend any time to learn how to use it, and then complain when it doesn't magically read their mind. It's leaky, like all abstractions. You have to understand how it works, and how databases works. There's always the option to write HQL or JPQL as well, or even fall back to SQL if all else fails.

It's not Hibernate's fault that you eager load everything, always load entire entities when you just need a single boolean field, or loop over entity collections to aggregate values - Hibernate is just a tool, and it's the developers who are telling it what to do.

Re:Java vs. Go performance by saiya-jin on Friday April 24, 2015 @04:14AM (#9432000)
true, but... if so many developers end up having issues on not-trivial-hello-world-employee-customer example, then maybe, but just maybe it's not the best tool for most. I mean, it's around for ages, the principle didn't change a bit, and same issues again and again.

One thing that I don't like about Hibernate - most projects evolve, for a very long time even after delivery. Messing with OR mappings (which most changes do) can include a lot of regression on performance side, much more than SQL (unless you do something horrible on DB level). Also, the more complex data model is (and often you don't choose how it's done), the less benefits you get from solutions like these.

Re:Java vs. Go performance by xtrumanx on Friday April 24, 2015 @04:31AM (#9432049)
What's wrong with having six lifecycle stages? I don't use JSF (or Java) but I can understand the usefulness of having several lifecycle methods assuming you can hook into them and add your own custom logic. The more lifecycle stages the more precisely you can choose when during the request processing your custom logic should be invoked.
Re:Java vs. Go performance by CookWithMe on Friday April 24, 2015 @05:48AM (#9432224)
You're right, there isn't anything wrong with the six stages per se.

The root cause is really that (a) they're forcing a stateful model onto the web and (b) that the way they're keeping/restoring the state is expensive.

The lifecycle stages are more a sympton of that. Most web framework these days go with a stateless approach. One notable exception is the lift framework for scala (although I'm not sure if it's really active anymore). I have only looked very briefly at it, but it seemed to give the programmer more explicit control of the state...

A simplified example to demonstrate the problem: Imagine a B2B app with a medium-sized table, where each row contains multiple objects. A HTTP request is send for performing an action on one object.

In a stateless approach, the programmer decides which objects he needs to serve the request. In JSF, the framework restores the complete state as seen in the previous request, and will also setup a lot of other magic (event handlers, validators, what not) - no matter whether it is actually needed to serve the request or not.

So one ends up with stages in the lifecycle that waste a lot of time, but one really hasn't much control over.

Re:Java vs. Go performance by xtrumanx on Friday April 24, 2015 @09:09AM (#9433025)
Oh sure, the stateful model thing you mention definitely sucks which is why I hate using asp.net web forms and prefer asp.net mvc at the office.

Both of them have lifecycle methods, (for app start, request start, request end, etc.) and for the most part I completely ignore them until the day I need to use them and I'm glad they exist because the alternative would have been writing a code in every endpoint of my application.

Re:Java vs. Go performance by fddlr on Friday April 24, 2015 @04:56AM (#9432106)
You don't have to use all Hibernate features. You can write your own SQLs too if you want to. Hibernate can be super fast if you use the correct strategies [1] at your bottlenecks. Any other performance issues are typically ORM related.

[1]: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/p...

Re:Java vs. Go performance by lmm on Friday April 24, 2015 @05:03AM (#9432121)
Any Java program takes a while to start up, and interactive Java desktop apps tend to be slow because of the UI toolkits they use. But in terms of throughput for a backend service, Java performance is fantastic.
Re:Java vs. Go performance by ghshephard on Friday April 24, 2015 @03:01AM (#9431794)
Once you heat up the JVM, Java can run like a bat out of hell. And, if you don't run into GC problems, it's as fast as anything out there.
Re:Java vs. Go performance by sacado2 on Friday April 24, 2015 @04:43AM (#9432077)
You can't fine-tune memory usage and can run into cache issues (or worse) if you deal with quite a lot of data, though.
Re:Java vs. Go performance by threeseed on Friday April 24, 2015 @05:26AM (#9432172)
Wait. What ? I have never seen any piece of technology with more tuning options than the JVM. Especially given how dramatically different your apps perform with different combinations. It's akin to old wifes tales about which settings to use when.

http://www.oracle.com/technetwork/articles/java/vmoptions-js...

And don't forget that much of big data is on the JVM e.g. Hadoop, Cassandra, HBase.

Re:Java vs. Go performance by lmm on Friday April 24, 2015 @05:05AM (#9432128)
> You can't fine-tune memory usage

What do you mean by that? There are some very fine-grained tuning options if you really need them.

Re:Java vs. Go performance by sacado2 on Tuesday April 28, 2015 @10:29AM (#9452595)
Maybe I'm wrong, but I don't know how you can say you want, say, a list of objects of class Foo be in contiguous slots of memory, rather than having a list of references to objects. Because the latter is very cache-unfriendly. In go, you can say whether you want a []Foo or a []*Foo
Re:Java vs. Go performance by lmm on Wednesday April 29, 2015 @03:14AM (#9456854)
You can do that "by hand" with buffers (and the HFT guys do) but yeah it's not easy or fun. C#-style struct types are supposedly coming in the next version.
Re:Java vs. Go performance by threeseed on Friday April 24, 2015 @02:55AM (#9431781)
That comes from the fact that Java takes quite a while to startup. It is going to be hopefully fixed in Java 9 where the platform becomes more modular. But that issue is what caused Java to have such a terrible reputation when apps were run on the desktop.
Re:Java vs. Go performance by hugi on Friday April 24, 2015 @03:48AM (#9431940)
Probably part of it, but for me, the somewhat uncanny valley-ish non-standard look and behaviour of Swing UIs (and AWT before that) is the biggest turn off. Using java apps on the desktop feels a little like using a keyboard with mittens.
Re:Java vs. Go performance by saiya-jin on Friday April 24, 2015 @04:23AM (#9432027)
This is an issue of unskilled devs using ancient UI design approach, usually not even bothering with skinning it.

Things like bitTorrent were done in Java (correct me if I'm wrong), and you have no clue which language they are done in when looking at UI. But this a bit of extra effort, and for intranet apps, nobody usually bothers.

Another reason for oh-not-so-windows-look of UI is something microsoft finally begun discovering - that there are other platforms than Windows. Java UI works anywhere where you have working JRE, and if you've ever seen Linux's KDE/GNOME/XFCE etc. then you might realize it ain't easy to come up with a cross-section between them.

You need to hack things with Wine or similar to have it +-++ work the other way around (ie MFC app -> anywhere but MS world, and even there it might be tricky with all dll hell).

Re:Java vs. Go performance by lmm on Friday April 24, 2015 @05:01AM (#9432114)
Standard bittorrent was in Python. Azureus was in Java and it felt significantly slower (than Python!) - it took so long to start it needed a splash screen, and you'd click a menu and wait for it to appear.

Kind of an unfair comparison - the Python one just calls native Qt or Tk whereas the Java UI is actually written in Java - but it does colour the perception.

Re:Java vs. Go performance by mike_hearn on Friday April 24, 2015 @05:07AM (#9432137)
Startup time isn't that bad. It takes about 500 msec to get a window on the screen with the latest versions of Java and the JavaFX toolkit. Most of that is UI init. If you're doing command line apps it's much faster.
Re:Java vs. Go performance by glogla on Friday April 24, 2015 @04:33AM (#9432057)
There's a series of articles about how Java don't have to be slow XML-laden crap: http://blog.paralleluniverse.co/2014/05/01/modern-java/

While I don't necessarily agree with everything in it (like Gradle builds), it's interesting to look at.

Re:Java vs. Go performance by vorg on Thursday May 07, 2015 @04:48PM (#9508193)
If you don't like XML but don't want to switch to Gradle, you could use another language atop Maven: https://github.com/takari/polyglot-maven