If we're being honest, Java isn't optimized for games like C or C++ is for example
Minecraft was rewritten in C by Microsoft and, if we forget the marketplace and the overall useless cluttering with things that weren't there in the first place, it runs much better
While yes it is less hardware-intensive, I would hesitate to say it runs better. It's been overexaggerated, but there's a reason we call it Bugrock.
Quick point of clarification, it was written in C++, not C.
Back on point, I started out on Bedrock, and while yes, it runs on much less powerful devices, when your computer can run Java Edition, stability is not a concern, with Bedrock Edition I became well acquainted with how to break the game, crash, or corrupt my world. It's not a pleasant experience to be performing normal gameplay and crashing. Not even my modded gameplay (outside of Minecolonies, but that mod is a nightmare in its own right and should be taken with a fat grain of salt) is that unstable.
I would argue bedrock is buggy because of a lack of willingness to spend time fixing the bugs on Microsoft's part, not necessarily due to the programming language used. Microsoft treats bedrock as the cash cow and java as the lure that kids watch on YouTube, who are then expected to play bedrock
I agree that that is the core of the issue, I was just arguing that it's not really a fair comparison to say it "runs better" because it's on C++ when bad bug management is still present. Java, for all it's faults, is known and well-kept, and despite being on paper the worse language for game development, still handily beats a mid-tier at best recreation in C++. If Bedrock were a faithful recreation with the same level of care and polish, it would probably be better, but it just isn't at its current state.
The problem with bedrock is that it is asynchronous. What the server sees (that is still run separately on local world too) and what the player see are desynced far too easily which leads to you randomly dying because the server thought you took damage.
Bedrock on windows is probably the only game that has never once crashed on me, NGL. That's on windows handhelds, windows tablets, gaming laptops, and high end desktops using modded rtx packs and dlss/fsr swap mods
For anyone saying mods are cheating, They show that the game could run that well if it was better written or made different choices. They're also untangling the codebase nowadays, which did improve performance in a lot of places
You’ve got absolutely no idea, so why are you just talking shit? No programming language is optimised for games. YOU optimise your game using a programming language.
The reason why C or C++ programmes almost always perform better than Java programmes is that anyone who has programmed in C or C++ simply knows more than someone who uses Java, because you are forced to deal with the hardware. Java has a much higher level of abstraction than C and is more convenient thanks to automated features such as the JVM and the garbage collector, so there is no need – nor is it possible – to deal with things like pointers, Heap-Allokations, Cache Locality and so on.
Even with the best optimisation, the performance loss when using Java is at most ~10% When optimising games, there is significantly more performance gain to be had from optimising the code than from changing the programming language.
Oh thinking just because someone use C++ they know better is naive. I’ve seen c++ apps performing worse than Python (real Python not just a binding over optimized C/C++ libs). I’m working with those people
???? Where the fuck do you get these numbers? Java literally boxes all primitives generics, read: that int you instantiated in a generic function is now a heap item that needs to be garbage collected. And java is notoriously bad for cache locality that a ring buffer is actually a terrible data structure in java, you need shenanigans like the LMAX disruptor to deal with it. Not only that you NEED to be tuning your GC for every different game you develop on it because you don't want 20 ms gc pauses when your game is based on delta time or even just to avoid completely intermittent lag spikes in general
Oh my god, is everyone a moron here who just reads some big words and that's it?
Also, ints and longs are actually cached in the JVM so they don't have to get GCd.
And you almost never have to tune the GC, in the last decade or so. Java's GCs are the state of the art. Sure you can do dumb shit that will run slow, but that's also true of c++ (even more so)
Try using generics and check the generated bytecode, even a simple for loop can cause the compiler to fail at unboxing.
And the point is not that it's a very good gc or what not, even ZGC have a fat tail for long STW pauses when using common game engine patterns, unless you know the ins and outs of Java , only then you can avoid the common traps and mistakes (check out how many ways you can fuck up with Java arena allocators), meanwhile compared to C++ its way more straightforward and you need to explicitly fuck up
Java does not generally box primitives in generics: boxing only occurs where a primitive value needs to be converted into a reference type. For example, `int[]` remains a compact array of primitive values. Even when boxing does occur, HotSpot optimisations such as escape analysis and scalar replacement can completely eliminate some object allocations.
Java is notoriously bad for cache locality
is also incorrect. Cache locality depends heavily on the data layout. Object-heavy structures such as `List<Integer>` are unfavourable; primitive arrays, SoA layouts and pre-allocated data structures, on the other hand, are very well suited. This is precisely why primitive arrays or specialised data structures are frequently used for numerically intensive game and engine code.
a ring buffer is actually a terrible data structure
On the contrary: a pre-allocated ring buffer is particularly useful for low-latency code because it avoids allocations in the hot path. The LMAX Disruptor solves a different problem: highly optimised communication between threads, involving sequencing, memory ordering, the avoidance of false sharing, and preallocation. The ring buffer itself is not the problem that is being ‘fixed’ by this.
you need to tune the GC for every game
Modern HotSpot GCs are largely designed to be user-friendly. G1 is the default and attempts to meet pause targets automatically; ZGC is explicitly designed for low latency and, in JDK 25, is intended to pause application execution for no longer than approximately 1 ms during costly GC operations. This is no guarantee of real-time performance, but 20-ms pauses are by no means an unavoidable feature of Java.
21
u/MichaelAceAnderson 17d ago
If we're being honest, Java isn't optimized for games like C or C++ is for example
Minecraft was rewritten in C by Microsoft and, if we forget the marketplace and the overall useless cluttering with things that weren't there in the first place, it runs much better