Recently I've tried playing minecraft once again, but i found out that the game itself uses much more memory than what i remember. It can be around GB on the main menu and once you load in a world it can jump to around 1.5-GB. It's a much bigger problem if i add mods in because it can go up to 8GB of usage while before with the exact same mods it went up to 4 (i have the -Xmx set to 4GB so it shouldn't go to 8). If you need logs or anything just ask me and i'll pass them because i don't know what i need to pass. Pics included below: Bug1 is on main menu, Bug2 is on world load (both 1.14.4) and Bug3 is the modded 1.12.2
If you last played the game years ago, say 1.7.10 or earlier, the game has become far more resource-hungry since then, mainly due to poor decisions made by Mojang when rewriting the game; many mods aren't exactly well-written either (for comparison, my self-modded version based on 1.6.4 uses 500-600 MB in Task Manager, with around half of 512 MB allocated used in-game, even on higher settings, e.g. 20 chunk render distance. Given what I've seen, I probably can't even run 1.14 since it would immediately hit the memory allocation limit for a 32 bit OS, around 1.5 GB, and otherwise risk running out of native memory (which I've experienced on 1.6.4 with 1 GB allocated with an in-game screen claiming that the game ran out of memory even though F3 said everything was fine. This never happened after I reduced the allocation).
Note that the memory allocated to the game is only a small part of the total memory used by the Java process, which includes the Java heap (the limit of which is set by -Xmx), the JVM itself, and memory used by native code, such as OpenGL (highly dependent on render distance and resolution and number of textures). This is why sp614x says you should not allocate more than half your system memory to the game (which should be free system memory, plus an additional buffer):
2. Why not give it more memory? Let's give Minecraft 4 GB of RAM to play with. This would need a PC with at least 8 GB RAM (as the real memory usage is almost double the memory visible in Java). If the VM decides to use all the memory, then it will increase the time between the garbage collections (20 sec instead of 4), but it will also increase the garbage collection time by 4, so every 20 seconds there will be one massive lag spike.
This link also explains some of the issues with versions since 1.8; other changes include block models, which force mods to either use a crazy number of models, each of which has a high overhead, or use tile entities for complex blocks with many states (this also affects vanilla, e.g. redstone dust used to be a single block with 16 metadata states (4 bits per block) and many "render-only" states (using a couple hundred lines of code to render it), but since 1.13 it is now 1296 separate blocks (over 5 times the total number of blocks in 1.12.2), each with its own block model in either case):
The general trend is that the developers do not care that much about memory allocation and use "best industry practices" without understanding the consequences. The standard reasoning being "immutables are good", "allocating new memory is faster than caching", "the garbage collector is so good these days" and so on.
Rendering system The old Notch code was straightforward and relatively easy to follow. The new rendering system is an over-engineered monster full of factories, builders, bakeries, baked items, managers, dispatchers, states, enums and layers. Object allocation is rampant, small objects are allocated like there is no tomorrow. No wonder that the garbage collector has to work so hard. On the positive side the rendering engine can load configurable block models and supports VBO rendering, which may be a bit faster. Because it is so complex there is a lot of optimization potential.
Chunk loading The multithreaded chunk loading is crude and it will need a lot of optimizations in order to behave properly. Currently it works best with multi-core systems, quad-core is optimal, dual-core suffers a bit and single-core CPUs are practically doomed with vanilla. Lag spikes are present with all types of CPU.
Thing is, it's weird because on the exact same version with the same mods, it never happened before. I feel like something went wrong with java but i already reverted to a much older version but it still happens...