r/ProgrammerHumor • • Oct 07 '26

Meme minecraftException

Post image
9.3k Upvotes

830 comments sorted by

View all comments

Show parent comment

34

u/coolraiman2 Oct 08 '26

Another issue for 3d rendering performance is that java does not have struct, everything is a class.

On the surface level ot does seems minor but a struct and a class are widely different on how its memory is allocated. Without a struct, calls to 3d rendering api are much less efficient

33

u/Lithl Oct 08 '26

JDK 28 adds inline classes, which give you the kind of memory allocation you'd expect from a struct.

It's not released yet, but the early access build is available. Build 18 came out last week.

27

u/coolraiman2 Oct 08 '26

20 years later but nice

10

u/LutimoDancer3459 Oct 08 '26

May i introduce you to project Valhallas value classes? Java is going stronger every release. Not long and the missing struct wont be an issue anymore

5

u/warpspeedSCP Oct 08 '26

If they can get the damn thing released maybe, its been what, a decade?

3

u/Cebular Oct 08 '26

I'm a C++ dev so struct/class really only differ in that class is private by default. What do you mean that java does not have struct?

1

u/coolraiman2 Oct 08 '26

For c++ the memory layout is the same but not for all other languages such a c#. And java class is equivalent to c# class

1

u/tecanec Oct 12 '26

That's specific to C++, which has relatively low overhead for classes to begin with. For languages with more overhead for classes, having a seperate system for structs can allow for significantly less overhead when things like polymorphism aren't necessary.

2

u/grimonce Oct 08 '26

This comment is so right and so wrong at the same time... Amazing

1

u/Ok-Scheme-913 Oct 09 '26

Inside the "3d rendering API" it doesn't fucking matter because it's memory you have to read from and copy to the GPU. Whether it's on stack or heap doesn't matter.

Flattening/layout can matter though and here java is indeed not in the best situation (though now they have value classes) - but you can always just go to a byte array and do your thing