News for hackers. Stuff that matters.
Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Tuesday November 11, 2014 @04:38PM (#8592361)
At runtime modern Java is around 10x slower than modern C++ (assuming both are fully optimised and the benchmark is relatively unbiased).

I don't think you can pick a single number like that, it depends very much on what the code is doing.

You probably got this 10x figure from a Google paper published a few years ago (https://days2011.scala-lang.org/sites/days2011/files/ws3-1-H...). Redux: the default out of the box 32 bit JVM (in 2011) was 12x slower than the same algorithm implemented in Java. But with a few simple GC flag changes, it became 3.7x slower. And then the Java version had a few further simple optimisations applied to the code and it became as fast as the original C++ version.

Meanwhile the C++ version was optimised again and became around 3x to 5x faster, but that version relied heavily on Google proprietary data structure code and could not be open sourced (!). So for most programmers on most projects, it seems likely to be a wash.

Meanwhile an alternative benchmark that reimplemented a non-trivial C++ program in Java found it became 1.09 to 1.5 times slower, but that was with Java 6 which is now two generations out of date:

http://www.best-of-robotics.org/pages/publications/gherardi1...

It would be interesting to get more recent benchmarks with the latest JVMs and C++ compilers.

Re:Vulnerability in Microsoft TLS library could allow remote... by TheLoneWolfling on Tuesday November 11, 2014 @10:50PM (#8593918)
As you say, it depends very much on what the code is doing.

In particular, anything requiring manipulating unsigned values all over the place will be a lot slower.

Also, see this[1] for talk about JGit. An actual project with direct comparisons.

[1] http://marc.info/?l=git&m=124111702609723

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @03:13AM (#8594481)
Those comparisons will be again out of date when Java 9+ comes out with value types, official unsafe package and lots of other goodies for performance being worked on.
Re:Vulnerability in Microsoft TLS library could allow remote... by mike_hearn on Wednesday November 12, 2014 @06:06AM (#8594871)
I'm not aware of any intent on adding unsigned types in Java 9 though. The lack of them is a real PITA, for sure. Not only for performance but it's incredibly easy to forget a & 0xFF here or there and introduce bugs.

The MMAP thing is also a good point. I believe HotSpot will compile the get methods on the MappedByteBuffer down to raw access so it shouldn't matter much for performance, in theory, but the code is still damned ugly. I never understood why they can't expose it as a byte[].

Re:Vulnerability in Microsoft TLS library could allow remote... by pjmlp on Wednesday November 12, 2014 @07:22AM (#8595083)
> I'm not aware of any intent on adding unsigned types in Java 9 though.

You kind of have them in Java 8, but not as primitive type.

https://blogs.oracle.com/darcy/entry/unsigned_api

I also think a very least having ubyte would be quite nice.

Apparently the reason behind the decision has to do with overflows and underflows in unsigned arithmetic.

Hotspot is just one of many Java native compilers out there , so it is better not to rely on what Hotspot does.

On the other hand, you can make use of JIT Watch or Solaris Studio debugging to see what Assembly is being generated.

> I never understood why they can't expose it as a byte[].

Maybe the official unsafe class will make this better.