Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I build fairly high-performance Java code. And get hit with three major gotchas which prevent it from approaching C code.

- There's no way to do array access without null pointer and index checks each and every time.

- Generics with basic types, and their unfortunate embedding into syntax (like the new for() syntax), are awful. Boxing and unboxing incur a ludicrously high penalty, and generics push coders away from using arrays. Unlike in C++, generics have been the enemy of performance.

- Poor quality collections classes (ArrayList and HashMap are notoriously bad)

Sure there's a few other things like pointer walking etc. in C, and Java's poor floating point, but the big three above are the killers.



> - There's no way to do array access without null pointer and index checks each and every time.

Actually there is. Have you checked out the sun.misc.Unsafe class? Lots of very dangerous gems in there, among them the ability to calculate array offsets and access the array elements directly. (check out arrayBaseOffset + arrayIndexScale + getObject/getLong/etc)


I would also add inability to create objects in stack, if you are doing anything recursive. The overhead of heap object creation is pretty visible. So I had to either reuse objects and essentially create my own memory management layer or try to stick data into primitive types which obfuscated code logic quite a bit.


Java 7 uses escape analysis to do stack allocation by default. So, if you play along and write code for which the escape analyzer can activate stack allocation (I don't know what the rules are for this), you can get those benefits.


I'd just like to point out that your complaints are specific to the Oracle JVM (except for the new for() syntax obviously).

Even the collection classes can change between JVM versions. I'm not saying that they're all necessarily better, just that different versions are different. So the Dalvik or IBM J9 versions might do what you want better.


> - There's no way to do array access without null pointer and index checks each and every time.

That's not happening anymore for years already.


??? There are easy ways to miscode your way around the optimizations.


But it's not true that "there's no way." I think that was the distinction being drawn here.


Okay, fair enough.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: