#Help getting my memory usage down even further
1 messages · Page 1 of 1 (latest)
Simply optimized is likely your best bet. There's a trade off all the time - you can add all the performance mods you want, testing along the way to see what actually helps and what may slow it down. If you go too far, things will break, your game will crash, and other mods will refuse to work.
It is a bit random but that 98 MB picture was just pure luck
I have been trying out some mods and 128MB gives nearly no room for anything
you're running on only 128mb?
thats gonna be rough whatever mods you install
i suppose you'll want to focus on memory-reducing mods like ferritecore
you could try a lower resolution texturepack and replace all sounds with blank sound files
Wouldn't that mess up mipmapping?
some sacrifices have to be made
You could probably make a mod that changes the entity and block entity view distance to extremely close amounts
I know that can improve memory usage somewhat
Now we're talking
hell remove the sun
skybox can just be a solid color to denote day or night
translucency? what for
Why render blocks at all?
ok but its minecraft we might want the block part
translucency is optional though
i have no clue how youd remove it
Minecraft can have just the selected block outline, as a treat
if you grayscale all rendering resources
thatll make a hefty impact
RGBA more like G
Not true removal but you could move every single block onto the solid renderlayer after they've been initialized
Not supposed to be done but it would work
youd ideally also run this on a server
flatland
not sure how singleplayer affects the ram usage
Modify the collision checks and raytracing to use quicker but less accurate math (Optifine moment)
disable entity rendering
they can hear entities purely through sound
oh wait what sound
use hitboxes
Disable entity spawning*
Nah
Too expensive, just throw the player into spectator mode so you don't need to do any collision checks
tell us how low your memory gets
you could probably turn minecraft into running at like, 8mb
just it wouldnt be minecraft
if space invaders can run on 8kb minecraft can run for a lot less
also you wont find any intelligent people here we're out of stock
try forgecord i heard they like dealing with random requests
or is it neocord now
Here is Minecraft in 4 kilobytes: https://web.archive.org/web/20150809054725/http://www.java-gaming.org/index.php?topic=21638.0
Minecraft 4k (very early build) - Java-Gaming.org
Also a JS implementation of the same thing: https://jsfiddle.net/uzMPU/
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
two upgrades to instantly boost yourself to a 1000 fps:
- remove lighting
- remove textures
Methane mod will do the first one
i love that
Has anyone ever tried running methane on a server 
Also, @rustic ermine I have this mod that may help reduce memory usage a bit. https://github.com/QPCrummer/McUnsafe. This mod doesn’t belong to me, I just updated a few things. It does some Mass ASM magic stuff to strings to make them more performant
Also, you can enable String deduplication in Java’s arguments:
-XX:+UseStringDeduplication
I have a mod idea
Disables lighting (keeps it at a fixed level that can be set in the config)
Can override simulation and render distance in the config
This config isn’t a menu
That is Methane’s job
This is a plain text file
Sounds like fun
Does it auto disable itself on servers
Nope, it just looks like full-bright
Is there a way to turn it off then
Oh, you mean if you run it on a server?
Well I mean if you join a server that doesn’t have it
Yes, it has a toggle button
methane would be great for singleplayer
I personally don’t use the mod, but I know it mentioned a toggle
It doesn’t matter. It only alters the client-side lighting engine
So it shouldn’t work on multiplayer that means
It works just fine on single or multiplayer
The server and client lighting things are entirely different I think
Yes, they work independently of each other
Great
Singleplayer: left image
Multiplayer: right image
I will add methane to my pack tomorrow
NBT data contributes to a good chunk of memory usage. I mean… I probably wouldn’t recommend deleting NBT from the game, but there are always optimizations that can be made (:
Deleting NBT for everything except for tile entities
NBT is used for a lot more than tile entities
Every single entity uses NBT
The world uses a lot of NBT
Health can be thrown out the window
Player inventories aren’t all that important
Just the hotbar mostly
I play in creative so no issues here
Actually, without a huge rewrite of the game. It wouldn’t ever be able to save any data at all. NBT is too important for MC to lose
Block updates
Removing block updates could be a viable option
Hmm
Blocks would just exist
You should be looking for things that either contain massive Lists of Objects, or a class that contains a ton of Objects and there are many instances of this class
Things would be normal except for water, lava and some things like grass and sand
So Block Updates really don’t cause that much memory usage
They can potentially cause memory usage
Their memory usage impact is extremely short term
You want to look for long term memory impacts
Eating the game is a bit extreme for what my target was for this
Such as loading files into memory (Aka NBT
)
i have another idea: why?
The game is weird
128mb seems like an arbitrary limit that doesnt obey any modern restrictions
It just kind of creeps up in terms or memory usage
The World class contains a List of every single entity in that world. (Do we need that
)
I honestly didn’t even know the JVM could function on 128mb of ram 
Screw BlockPos just use an int array


I'm not even kidding

if it overflows it overflows
Minecraft shorts
the client doesnt need to know any of that though?
Yeah, I don’t believe the client touches NBT
Actually BlockPos would probably not change size now that I think of it
Cause a class header is 12 bytes, and the array header is 8 bytes and 4 bytes for the size
But this. I can see the potential already 
The one word came into my peanut sized brain
AlphaMode is trying to make the MC game bigger. We are making the MC game smaller 
Stripelands
its pretty much just client optimization though
nah thats floating point issues
How much do textures affect ram usage though. I thought they only affected VRAM usage
^
Well… doesn’t help either.
I doubt it would be significantly noticeable
Sodium is laughably fast
It would be if you disabled the render type changes
Would not reduce memory tho
You could strip a bunch of stuff from Direction
Large enum used heavily in the source
however its an enum so not many allocation
Oh also make sure to get rid of MemoryReserve
What’s that
It's used to prevent the client from hard crashing by keeping a ton of memory reserved
I would want the game to forget everything after you leave a world

Exactly as if you restarted the game
Then perfect, screw it
Kill this
Find a way to get rid of that
I really wonder how well that could work out

It can easily be done, just remove all bytecode mentioning that class to prevent it from being loaded
I might get as much as a 20mb memory decrease
Someone needs to actually do this now
Is it possible for you to create a small mod to do that
I'm too busy with work
I have code that could probably help redirect the class here:
https://github.com/fxmorin/ExperimentalPerformance
Btw this mod does not reduce memory, it simply shifts it around to optimize the cpu cache lines
Actually technically that mod increases the memory usage due to class headers xD
you could technically do the reverse of it and merge classes together to remove class headers
That's a whole 12 bytes per class allocation right there
Oh btw, people say that the mod is working on 1.20, but I could’ve sworn that it gave errors when trying to mess with bytecode in 1.20. Do you know if it should still work?
I think it should, the core system def does. Not sure about the groups I made tho
Might be a cool idea to make it load those groups from a json file so that people can jsut use it if they want to
Interesting. ChunkPos could actually be less memory by turning it into an array
@rustic ermine I implemented this in my mod I am making. You will need to enable it in the config using: mixin.memory.memory_reserve = true since this is likely to break many things on low amounts of dedicated ram. https://github.com/Tater-Certified/Potatoptimize You'll need to compile it from source as it is an experimental mod currently
it looks like you just want something very similar to minecraft classic but with modern blocks/textures etc.
I want modern Minecraft
But on 128mb of memory
Once it’s out of an experimental stage I might try it
i know it just seems like how everyone is describing it is just downdating the game lmao
yeah, I feel like removing gameplay features is against the goal (kinda like how it's easy to get 1000fps in minecraft if you have nothing to render in the firse place). Like in the initial post, it's just a flat world rather than naturally generated terrain, including mobs, which seems a little bit cheaty for trying to reduce memory usage. I think it should at least still be a playable game rather than empty world.
Now, I know world gen is THE thing that causes the most memory pressure for TONS of shortly lived objects, but you can avoid this by pregenerating the world (slowly, to give the GC time to quickly remove garbage to maintain a low maximum). And only with the paper server open and client not running to save memory to use for world gen. Then play with the world border enabled to prevent world gen during gameplay
one slightly more crazy idea if you want to bend the rules a bit is you can experiment with non-vanilla world generation. Like for example, you can try the "Terra" fabric/paper plugin with whatever that default overworld pack is called. Since it's a completely custom world generation engine, it will likely have wildly different memory usage characteristics than vanilla.
You can also set an extremely aggressive GC
That feature is finalized... since the entire idea of it is to be unsafe. You can disable every other feature of the mod using my lithium-like config as show here: https://github.com/Tater-Certified/Potatoptimize/wiki/Configuration-File
@rapid trout pretty sure Xoroshiro128 is slower than Java random
Especially minecrafts as it does an extra step in there
Btw if we are targeting memory and not performance. Could nuke a couple caches
I am mostly targeting performance as that memory option is disabled by default
You sure? I could’ve sworn that Xoroshiro’s was the fastest around
Oh yeah, I forgot. You had your own special version of Xoroshiro’s random. I should probably take a peek at that
I like how everything is: “Minecraft’s <insert feature> is even worse” 
Ya Java random is a lattice which is pretty damn fast
You can use ThreadLocalRandom tho if you want it to be faster
Hmm, I got conflicting viewpoints from that
I was told ThreadLocalRandom was slower than Xoroshiro
@unborn crest tell us your secrets
Ooo, that Wutax man 
what's the question
Ok, I think there is a way to make ThreadLocalRandom to be faster. I was explained it, but it’ll take a bit to understand it 
Best implementation of random, I think?
define "best"
Performance, as in the quickest to generate a random number
So Xoroshiro is slower than Java random?
Someone said this to me: “Frankly I think the LCG of Java's random will be the fastest if you remove the synchronisation overhead”
depends on the implementation, but generally speaking yes LCGs are faster
Specifically minecrafts xD
Thats what threadlocal basically is
kinda hard to compare the performance of a synchronized method vs non sychronized
i would place my bets on java random though ye
Ok good, I was remembering correctly
whats the worry though? RNG call overhead should be virtually inexistent
¯_(ツ)_/¯
So what you are telling me is Mojang chose to make an entire class… instead of using ThreadLocalRandom when it is “better”?
Idk, just practicing coding
Yes for compatibility tho
They need it to be the same between bedrock and java edition
they made their own class so they can overwrite behaviour and integrate it with their random API
but ye if you wanna tryhard this keep a long seed object around and plug it through static helpers
that's what I did for programs that needed a shit ton of random instances
just a long[] and run vector operations on it
idk the use case here though
Just trying stuff out
Also I was using the FasterRandom mod, but it is now discontinued
So it just got my brain thinking on if I could make it better
Lmao FastRandom mod uses slower random

Epic
Wait
But it uses ThreadRandomLocal, right?
At least I recall it claiming to use that
Ohh that would be faster
ThreadRandomLocal is whack, would not recommend
lol
either use java.util.Random or mojang's thing
depending on context
if the goal is to optimize world gen there's about 50 million meaningful optimizations you can do before worrying about RNG tbf
Nah its client-side MathHelper random it seems
Yeah
I never touch world generation ever again 
Basically all I am doing is trying things out in my mod. If MC goes faster, cool! If not, also cool! The more I know, the better I will become 
show the code
I’ve just been listening around the community to ideas (mainly 2No)
and where is that nextInt being used client side, i only remember server side uses
MathHelper is used everywhere, I think?
no i mean the nextInt code
of mathhelper
i assume thats the one youre trying to optimize right?
I just replaced all of the methods in MathHelper
But
Now that I know a bit more from you guys, I realized that my method is possibly worse than the regular version
Not sure how to do code blocks on mobile, but it is on line 40 https://github.com/Tater-Certified/Potatoptimize/blob/main/src/main/java/com/github/tatercertified/potatoptimize/mixin/random/RandomMathHelperMixin.java
public static int nextInt(Random random, int min, int max) {
if (min >= max) {
return min;
}
return random.nextInt(max - min + 1) + min;
}
i mean youve completely destroyed the contract of that method
I tried ):
its completely ignoring random
@Inject(method = "nextInt", at = @At("HEAD"), cancellable = true)
private static void optimizedNextInt(Random random, int min, int max, CallbackInfoReturnable<Integer> cir) {
if (min >= max) {
cir.setReturnValue(min);
}
cir.setReturnValue(FastRandom.fastRandom.nextBetween(min, max));
}
like
the random parameter is being ignored
Yeah, it is a Mixin
I’m not sure if I can replace that?
Unless you mean I should Mixin up further in the code to change “random”?
that's not what Im saying, youre just not respecting the internal state of Random
this will cause a lot of world gen features to become completely random instead of respecting seed
huh
Lemme find the code I’m talking about
OH
Wait

I forgot to move some code from my test project
Normally I set the seed at server start
Sorry for the confusion
that doesn't do anything
do you understand why MathHelper.nextInt() takes in a Random parameter?
I guess not
I see that it is used in the return method for generating a random int between two numbers
ye
But I guess you are suggesting that “random” contains data that I don’t have in my implementation?
Random has an internal state, that generates a pseudorandom sequence of numbers
so if i do:
Random random = new Random(12345L);
return MathHelper.nextInt(random, 0, 5);
I am always expecting the same number back
with your mixin though it ignores that parameter and returns whatever it wants
Oh btw, before we get too far, I don’t plan on maintaining vanilla parity. But I do want you to continue on because I am a curious individual 
Oh yeah! That is how speed-runners can go into the same world and get the same exact randoms. I’ve heard of this before
So does MC store the position where Random left off when the server shuts down?
Because I am surely not currently 
no, it uses procedural generation
there is no 1 random instance
the game creates Randoms on the fly
well you cant do procedural generation with 1 random
that creates an order dependence
Hmm. I guess I’m not fully understanding the “procedural generation” part
I understand it is how computers generate “things”
But that is the extent of my knowledge
procedural generation isn't easy to explain, you're gonna have to do some research
buuut the important thing is that you understand how Random works for this
Wait, are all instances of Random somehow linked together?
I honestly don't see the performance impact of MathHelper at all, you're trading world gen reliability for a couple of nanoseconds even if you do it perfectly. Plus this is a massive headache for modders who call that method.
Oh. I guess I’ll get rid of it. I was just wanting to mess around with Random
I did do CUDA acceleration with Random 
But I had to stop the real quick 
I couldn’t figure out how to do batches of random numbers because transferring data between the CPU and GPU every random was way too awful

But I learned new things, and that was my goal
Oh @unborn crest Thanks for helping explain things for me! I really appreciate you explaining in depth for me 
And also @vast gale, thank you too
GPU random???
you're gonna be spending more time building a buffer than just doing the call 
Yes, I realized that afterward 
But it was fun getting that to work
And for some reason random longs never worked 
That moment when random is random
You mean an int array of int arrays of int arrays for a 3D matrix 
Side note, this 128MB business makes me want to try running the Java edition on my old Raspberry Pi 3
bro is running on a raspi zero 🗿
i really don't understand why you're cranking the allocation so low
even the worst pentiums have at least 2GB RAM nowadays
if most of your end users, or you, have anything less than 1GB RAM, then they have much bigger issues
they would likely run integrated graphics with a dual core leapfrog lookin laptop from 2001
and even then, their framerate will be like a powerpoint presentation in best conditions. it's just not worth your time optimizing the pack that much
Even a Raspberry Pi Zero should theoretically have more than 128MB to allocate lol
bro is running on a microcontroller 🗿
I think it is a joke… I hope 
You can pack it
2 ints into a single long is trivial
MC does this in a lot of places
But I guess not all
JVM memory usage is still like 100 MB though sadly
Probably could get less with OpenJ9
I enjoy playing Minecraft on 128mb of memory
Even though I have 32GB of total RAM
@rustic ermine Try with OpenJ9

