How can I find the cause of lag in my singleplayer world in Minecraft?

Solution 1:

First off, diagnosing the lag. There are two main factors, client-side rendering - framerate drop, frames per second, "FPS", marked in yellow on the screenshot below (debug screen, press F3), and server-side lag (even in single-player, your game just launches a local server) - time it takes to calculate a game tick, milliseconds per tick, MSPT, marked in red. Additionally, primary source of both forms of lag is excessive number of entities, the entry 'E:' marked in magenta, displaying entities within view range of the player, and a total present in the loaded chunks.

enter image description here

By turning around and observing the first number of the E entry you can see when an area with an excess of entities enters your field of view. Move to a different place, repeat the procedure and you can triangulate the location with too many entities. It may be an animal farm, it may be a water stream out of one of your farms, with a fault where items accumulate, it may be underperforming collection system, or it may be a room lined with hundreds of item frames, a mob farm disabled by turning its kill system instead of lighting or otherwise spawn-proofing the spawn floors, or a massive kelp farm in operation, producing thousands of kelp pieces by breaking the kelp plants.

Other than that, lots of transparent blocks - including chests, mixed layers of glass (as opposed to solid chunk of glass), a big block of leaves, slime blocks and similar can cause FPS drop. Again, you can triangulate the culprit by turning and observing what enters your view when your framerate drops. Additionally, lots of particles can cause framerate drop - a large number of campfires, bubble columns, or other sources of particles can cause that.

Reducing server lag (mspt) is trickier, as besides entities there are other sources of this sort of lag. The primary culprits beyond accumulation of entities are a lot of fast-pulsing redstone dust, and minecarts with hoppers, although a large number of regular hoppers, chests, frequently toggled light sources that effectively change lighting of their surroundings (e.g. redstone torches in otherwise unlit contraptions) and many other problems a bit too numerous and situational to list.

Solution 2:

The chunks around spawn are always loaded which means that any redstone machines you've built in those chunks are always running.

My suggestion is to create a copy of the world, go into creative and remove all the redstone machines from the spawn area. This will tell you if the lag was caused by your redstone machines.

Solution 3:

A possible problem is that there are too many blocks being rendered at once, making Minecraft lag. Try checking if all your machines are off and the amount of mobs on your screen (100 or more would cause a problem). There could be too many things happening at once. I encountered this problem once when my cousin spawned too many withers — the horror!