Why Does Minecraft Lag?

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here

Saamoz

New Member
Jul 29, 2019
25
0
0
Now first of all, this probably isn't a question I should be asking in general FTB chat, or even in the FTB forums at all. The people here, however, have lot's of experience with modding, so I find this place to be better for more complex questions.
Anyway, when was the last time you bought a GPU? Many different GPUs boast features like "Voxel Global Illumination", or "Multi-Frame Sampled Anti Aliasing", or things like "Tiled Resources" or "Advanced Sampling". These things are all very expensive, I'm sure (although I can't tell if they're essential or gimmicks), but how do they actually affect game performance? I've heard that voxel global illumination can provide realistic lighting and realtime illumination rendering, but how much of this stuff affects games created before the GPU?
Minecraft is a very different game, from what I can work out. Other games are built to use as many of these features as possible, but does minecraft use any of these advanced GPU features? That's my first question, by the way.
I'd suppose not, since I've heard that minecraft is CPU based. In fact, all of Java is CPU based. Second question: how is Java more CPU based than other languages? Don't they all just convert source code into machine language?
Unfortunately, a lot of this is minecraft's fault. People say that it's inefficient. Others say that it's really hard to build an efficient voxel-based engine. How is minecraft inefficient exactly, and how could it be more efficient?
This is where multi-threading comes into play. Final question: what is the difference between true multicore support and multi-threading? What exactly is a thread?

I have some knowledge of coding theory, so don't be afraid to explain in programmer concepts.
 
  • Like
Reactions: ThatOneSlowking

Cptqrk

Popular Member
Aug 24, 2013
1,420
646
138
Now first of all, this probably isn't a question I should be asking in general FTB chat, or even in the FTB forums at all. The people here, however, have lot's of experience with modding, so I find this place to be better for more complex questions.
Anyway, when was the last time you bought a GPU? Many different GPUs boast features like "Voxel Global Illumination", or "Multi-Frame Sampled Anti Aliasing", or things like "Tiled Resources" or "Advanced Sampling". These things are all very expensive, I'm sure (although I can't tell if they're essential or gimmicks), but how do they actually affect game performance? I've heard that voxel global illumination can provide realistic lighting and realtime illumination rendering, but how much of this stuff affects games created before the GPU?
Minecraft is a very different game, from what I can work out. Other games are built to use as many of these features as possible, but does minecraft use any of these advanced GPU features? That's my first question, by the way.
I'd suppose not, since I've heard that minecraft is CPU based. In fact, all of Java is CPU based. Second question: how is Java more CPU based than other languages? Don't they all just convert source code into machine language?
Unfortunately, a lot of this is minecraft's fault. People say that it's inefficient. Others say that it's really hard to build an efficient voxel-based engine. How is minecraft inefficient exactly, and how could it be more efficient?
This is where multi-threading comes into play. Final question: what is the difference between true multicore support and multi-threading? What exactly is a thread?

I have some knowledge of coding theory, so don't be afraid to explain in programmer concepts.

You have answered some of your own questions, in a way :) I'm no expert but this is what I can contribute.

Minecraft by default doesn't use your GPU, so it is all working off your CPU. This can be fixed by going into your graphics card software, and setting it to recognize java as a program needing the GPU. This causes lag because everything the game is doing, must run through one core/thread on your CPU.

Java itself isn't "more CPU based" (as far as I'm aware) than other programming languages. The thing with Minecraft is, that it just wasn't meant to get this big. It wasn't coded to use multi-core because it was never intended to be this behemoth that it's become. It surely wasn't coded to be modded either. If Minecraft was planed out to be a AAA game, it would (still be buggy as hell LOL AAA games LOL) have been coded differently from the ground up.
 
  • Like
Reactions: ThatOneSlowking

Saamoz

New Member
Jul 29, 2019
25
0
0
So if you set minecraft to use your GPU, it will be less laggy? Then how come people still complain about CPU lag when they can do this simple step? And people are advised to buy good CPUs?
Are most AAA games made multicore? I can imagine what a nightmare that would become. How is true multicore more efficient than the multithreading that Mojang recently added? I'd imagine a lot of changes in code and optimization happened between 1.7 and 1.8. In a very basic sense, how is coding for multicore different than singlecore?
 

Cptqrk

Popular Member
Aug 24, 2013
1,420
646
138
Setting your GPU to recognize java is one of the tweaks people use to help with their FPS.
The thing is, this is just for rendering. There are many things that cause lag but some of it is related to rendering entities that store a data value. Thus, not GPU, but CPU heavy items.

Also Minecraft is... weird... One example of it is in Etho's recent video from the Mindcrack server where he went and did some lag busting. Signs (and other entities such as chests, banners, hoppers etc. that store a data value) are rendered by the Minecraft engine, even if they are not visible. He even goes into a test world, builds a wall and puts a lot of signs behind it. No text, just signs. Looking at the wall, he can't see them, but the rendering engine goes nuts trying to draw all the signs he can't see. Even a blank sign had extra information due to it's ability to be positioned in 8 different ways, and it's need to show that there is text, or even no text.
I'm not sure if mods can fix this, but I'm sure mods are also constrained by this, as a lot of the mods add these entities.

Now when it comes to threading and cores, well, you will have to ask someone else that.. As Forrest Gump said, "I'm not a smart man".

**Edited**
Because I derped :)
 

rungok

New Member
Jul 29, 2019
173
0
0
Setting your GPU to recognize java is one of the tweaks people use to help with their FPS.
The thing is, this is just for rendering. There are many things that cause lag but some of it is related to rendering entities that store a data value. Thus, not GPU, but CPU heavy items.

I didn't know about this. I'm going to give it a shot so my laptop has a chance of running on the modded server.

I did get a bit of a performance boost with Optifine running. Is there a way to fix the signs issue?
 

FyberOptic

New Member
Jul 29, 2019
524
0
0
Java is considered "slower" than other languages like C/C++ because it's compiled down to instructions which are executed inside of a virtual machine (sort of like an emulator), as opposed to being compiled into instructions which are executed directly by your CPU. Being run inside of a virtual machine is what gives Java most of its cross-platform capability, because a JVM can be written for just about any platform.

But it's always an incorrect assumption to say that this automatically means Java will perform worse, because the manner in which something is developed can make all of the difference. If you put a bunch of bloated abstraction layers and libraries in your C++ code, you can end up with some pretty piss-poor performance just the same. You also have to take into account that things like OpenGL calls in Java are handled by native libraries, so you have higher performance than normal in those instances. The JVM itself is also pretty optimized these days. So I won't say that a version of Minecraft written in C++ wouldn't run better, but I can say that we haven't really seen one yet that does.

A thread is basically code in a program being executed simultaneously as other parts of the program. These don't inherently have any sense of processor cores, they simply do their thing, even if that's on the same processor core as the other thread(s) of the program. It's generally up to the OS to decide the most efficient place to run the thread from. Minecraft has had a few threads for a handful of things for a while now, but it's only starting with 1.8 that they really tried to break up the most intensive parts of the game into threads (the chunk rendering, particularly). Breaking something into threads doesn't automatically mean better performance, though, because you have to use programming techniques to "stall" the other threads from accessing parts of memory that another thread is actively trying to use. This can even lead to worse performance than a single-thread, depending on the software and hardware involved.

No fancy modern video card features are really going to help Minecraft much. As long as you have a decent card capable of pushing a moderate amount of vertices at a respectable rate then that's really all Minecraft cares about. Even the newer additions to the game, like shaders, aren't taking much advantage of what a modern video card is capable of. Minecraft doesn't use fancy lighting because it needs the software-based method to determine things like mob spawns and plant growth, things which techniques like shadow mapping don't easily provide for. 1.8 makes some significant strides to move away from some of the old traditional fixed pipeline OpenGL calls, but we're still using technology from years ago. The newer VBO system that you can enable instead of render lists is only better depending on the hardware it's used on. But it's going to come in handy on down the road for them to implement a better shader pipeline for fancier rendering techniques. All in all, Minecraft has historically never used very fancy stuff in regards to rendering, but that's mostly because it never really needed to.

Hopefully that helps answer some of your questions!
 
  • Like
Reactions: RedBoss and Cptqrk

Cptqrk

Popular Member
Aug 24, 2013
1,420
646
138
I didn't know about this. I'm going to give it a shot so my laptop has a chance of running on the modded server.

I did get a bit of a performance boost with Optifine running. Is there a way to fix the signs issue?

Optifine is hit or miss for many folks. The sign issue though, is built into vanilla... I'm not sure there is anything modders can do.
 

rungok

New Member
Jul 29, 2019
173
0
0
Oh okay. I've recently been having these weird graphical fluctuations where for a moment my entire screen shows through to the tunnels and stuff under the earth, with weird texures in the background. Trying to figure out which mod is doing that
 

Saamoz

New Member
Jul 29, 2019
25
0
0
Well, wouldn't it be a simple change somewhere in the rendering code to stop things from being rendered if no players are looking at it? Even if it's not so simple, it would be worth it to fix massive lag issues. Couldn't modders do this also; they've hooked into minecraft rendering code without forge many times before. Also, signs shouldn't be a big problem when not being rendered. All entities have values like their x, y, and z positions, health, direction, and much more. In modded mc, players have much, much more data than normal (I'm looking at you, thaumcraft and ars magica).
So how would inherent multicore support be different than putting everything on a thread. If I'm interpreting you correctly, it's actually worse to make things multicore because than you'll always have to check every other core and stall all of the thread's function to make sure there aren't any bugs or glitches.
If minecraft was rewritten from the ground up to handle massive entity counts and torrents of data from machines and wires and magic, would it be different than it is now. Developers have already put countless hours into optimizations and performance, so how would a rewrite be different than the everyday optimization update?
 

ratchet freak

Well-Known Member
Nov 11, 2012
1,198
243
79
you can check the frustum to see if the renderable BB is in it (read: you are looking in the general direction of the object) but it won't stop occluded signs from being rendered.

nowadays the depth buffer is the fastest way to check whether or not to draw a pixel and software occlusion check is expensive (there are GPU callbacks but that stalls (read stops) the GPU and will cause more lag, that was the advanced GPU setting)

there is a new technique that allows the CPU to say whether or not to draw a certain 16x16x16 chunk based on which way you are looking and solid blocks in the chunk but apparently it's not used to exclude Tile entities from rendering (can anyone confirm that last bit?). You could use it for that but some TEs have render boxes outside their own tile (beacons to mention one)

You could make a multithreaded voxel engine but that is a pain to avoid race conditions, unless you specify a max kernel each tile can affect (read and write) and lock all those tiles before running the main code of the tile each time. That takes time you don't need to spend with a single threaded design.
 

Hambeau

Over-Achiever
Jul 24, 2013
2,598
1,531
213
Well, wouldn't it be a simple change somewhere in the rendering code to stop things from being rendered if no players are looking at it? <<< This is one of the additions made to Chunk generation and rendering in MC 1.8 >>> Even if it's not so simple, it would be worth it to fix massive lag issues. Couldn't modders do this also; they've hooked into minecraft rendering code without forge many times before. Also, signs shouldn't be a big problem when not being rendered. All entities have values like their x, y, and z positions, health, direction, and much more. In modded mc, players have much, much more data than normal (I'm looking at you, thaumcraft and ars magica).
So how would inherent multicore support be different than putting everything on a thread. If I'm interpreting you correctly, it's actually worse to make things multicore because than you'll always have to check every other core and stall all of the thread's function to make sure there aren't any bugs or glitches.
If minecraft was rewritten from the ground up to handle massive entity counts and torrents of data from machines and wires and magic, would it be different than it is now. Developers have already put countless hours into optimizations and performance, so how would a rewrite be different than the everyday optimization update?

As I understand things, threads have to be prevented from conflicting with other threads, while each core in a multicore environment actually maintains its own set of threads, and if the OS multicore support is properly written threads on one core cannot conflict with threads on another. However, Good multicore support is a whole different problem altogether.
 

ratchet freak

Well-Known Member
Nov 11, 2012
1,198
243
79
As I understand things, threads have to be prevented from conflicting with other threads, while each core in a multicore environment actually maintains its own set of threads, and if the OS multicore support is properly written threads on one core cannot conflict with threads on another. However, Good multicore support is a whole different problem altogether.


multi core vs. multi thread is entirely up to the OS and affinity of the processes/application

it's the OS that distributes the work threads do over the cores if you are multithreaded then you will also be multi core if you have a multi core CPU, the synchronisation techniques programmer-side are entirely the same (for backwards compatibility of single core programs)
 

Oxygene

New Member
Jul 29, 2019
12
0
0
How about startup time? I've heard that the startup process involves compiling the game, isnt there a way to save this in memory already compiled or something? I may just be talking nonsense but I need to reset minecraft on 1.7.10 a lot atm as crafting lag happens often and the startup takes so long... With my machine it is depressing!