Hacker News new | ask | show | jobs
by bunderbunder 5183 days ago
The claim that Objects have 'too much' overhead is subjective - but also basically wrong.

I don't know if this is what the author originally intended, but as a most-of-the-time .NET programmer, I do see one glaring flaw to Java that falls along these lines, and which I believe is inherited from the JVM (I've heard of it being a problem for people trying to write a C# compiler that targets the JVM): There's no concept of a user defined pass-by-value type. There are only primitive types and reference types (i.e., objects).

This does create some overhead. It means that for any instance of a user-defined type you have to use additional resources in two ways which may be unnecessary: First, it goes on the heap, so it invariably adds to the garbage collector's workload. Second, it's always going to be internally referenced indirectly via a pointer. That's an extra 4-8 bytes that could be significant overhead for a sufficiently small type - say, a struct that represents an RGBA value as four separate bytes. That's also poorer locality of reference, in a way that I suspect could bite when you're dealing with large collections of small elements.

1 comments

> There's no concept of a user defined pass-by-value type.

Everything is pass-by-value, but I understand what I mean.

> Second paragraph ...

Yes, it all sounds legit. But in reality, it is often quite different and after the JIT compiler ran not a single object allocation or dereference is left. It's not like JVM engineers are stupid, you know. :-)