#Help getting my memory usage down even further

1 messages · Page 1 of 1 (latest)

rustic ermine
#

I need intelligent people to help me find the optimal mod list

indigo trail
#

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.

rustic ermine
#

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

unique gull
#

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

novel widget
#

you could try a lower resolution texturepack and replace all sounds with blank sound files

trim birch
#

1px textures

#

no sounds

faint wraith
#

Wouldn't that mess up mipmapping?

trim birch
#

some sacrifices have to be made

faint wraith
#

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

trim birch
#

remove block entity renderers

#

entirely

#

no atmosphere, no particles

faint wraith
#

Now we're talking

trim birch
#

hell remove the sun

#

skybox can just be a solid color to denote day or night

#

translucency? what for

faint wraith
#

Why render blocks at all?

trim birch
#

ok but its minecraft we might want the block part

#

translucency is optional though

#

i have no clue how youd remove it

faint wraith
trim birch
#

if you grayscale all rendering resources

#

thatll make a hefty impact

#

RGBA more like G

faint wraith
#

Not supposed to be done but it would work

trim birch
#

youd ideally also run this on a server

#

flatland

#

not sure how singleplayer affects the ram usage

faint wraith
#

Modify the collision checks and raytracing to use quicker but less accurate math (Optifine moment)

trim birch
#

disable entity rendering

#

they can hear entities purely through sound

#

oh wait what sound

#

use hitboxes

faint wraith
trim birch
#

well youd still want pigs and cows

#

they are a core mechanic

faint wraith
#

Nah

trim birch
#

also all blocks are solid

#

like 1x1x1

faint wraith
trim birch
#

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

faint wraith
trim birch
#

two upgrades to instantly boost yourself to a 1000 fps:

  • remove lighting
  • remove textures
faint wraith
#

Methane mod will do the first one

trim birch
#

i love that

faint wraith
#

I love optimization mods that don't care for Vanilla parity

#

Lol

rapid trout
#

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

rustic ermine
#

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

rustic ermine
#

This is a plain text file

rustic ermine
#

Does it auto disable itself on servers

rapid trout
#

Nope, it just looks like full-bright

rustic ermine
#

Is there a way to turn it off then

rapid trout
#

Oh, you mean if you run it on a server?

rustic ermine
#

Well I mean if you join a server that doesn’t have it

rapid trout
rustic ermine
#

Good

#

Where

#

A keybind?

rapid trout
#

Yes

#

I think?

rustic ermine
#

methane would be great for singleplayer

rapid trout
#

I personally don’t use the mod, but I know it mentioned a toggle

rapid trout
rustic ermine
rapid trout
#

It works just fine on single or multiplayer

rustic ermine
#

The server and client lighting things are entirely different I think

rapid trout
#

Yes, they work independently of each other

rustic ermine
#

Great

#

Singleplayer: left image
Multiplayer: right image

#

I will add methane to my pack tomorrow

rapid trout
#

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 (:

rustic ermine
#

Deleting NBT for everything except for tile entities

rapid trout
#

NBT is used for a lot more than tile entities

#

Every single entity uses NBT

#

The world uses a lot of NBT

rustic ermine
#

Health can be thrown out the window

rapid trout
#

And your inventory

rustic ermine
#

Player inventories aren’t all that important

#

Just the hotbar mostly

#

I play in creative so no issues here

rapid trout
#

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

rustic ermine
#

Block updates

rapid trout
#

Unless you made a very similar Json-based alternative

#

Those don’t rely on NBT

rustic ermine
rapid trout
#

Hmm

rustic ermine
#

Blocks would just exist

rapid trout
#

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

rustic ermine
#

Things would be normal except for water, lava and some things like grass and sand

rapid trout
#

So Block Updates really don’t cause that much memory usage

rustic ermine
#

They can potentially cause memory usage

rapid trout
#

Their memory usage impact is extremely short term

#

You want to look for long term memory impacts

rustic ermine
#

Eating the game is a bit extreme for what my target was for this

rapid trout
#

Such as loading files into memory (Aka NBT tiny_potato)

rustic ermine
#

I have an idea

#

A button that instantly refreshes the game to clear out memory

trim birch
#

i have another idea: why?

rustic ermine
#

The game is weird

trim birch
#

128mb seems like an arbitrary limit that doesnt obey any modern restrictions

rustic ermine
rapid trout
#

The World class contains a List of every single entity in that world. (Do we need that widetater)

rapid trout
vast gale
#

Screw BlockPos just use an int array

rustic ermine
rapid trout
vast gale
#

I'm not even kidding

rapid trout
rustic ermine
#

Would integer overflows and certain issues occur sooner than usual

#

(Before 2^31)

trim birch
#

if it overflows it overflows

rustic ermine
#

2147483647 -> -2147483648

#
  • an extra crash
rapid trout
#

Oh I know. Remove every Map in MC’s code yeefuckinhaw

#

Convert all numbers into shorts

rustic ermine
#

Minecraft shorts

trim birch
rapid trout
#

Yeah, I don’t believe the client touches NBT

vast gale
#

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

rapid trout
vast gale
#

I mean yes

#

You will get edge case issues tho

rustic ermine
#

The one word came into my peanut sized brain

rapid trout
#

AlphaMode is trying to make the MC game bigger. We are making the MC game smaller tiny_potato

rustic ermine
trim birch
#

its pretty much just client optimization though

vast gale
#

nah thats floating point issues

trim birch
#

so just remove textures and lighting

#

unless you're talking server-side optimizations

rapid trout
vast gale
#

^

trim birch
#

doesnt hurt

#

higher fps

rapid trout
#

Well… doesn’t help either.

rapid trout
#

Sodium is laughably fast

vast gale
#

It would be if you disabled the render type changes

rapid trout
#

Well yes, just remove OpenGL

vast gale
#

Would not reduce memory tho

rapid trout
#

Minecraft: The Blank Canvas

#

It is truly limitless

vast gale
#

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

rustic ermine
#

What’s that

vast gale
#

It's used to prevent the client from hard crashing by keeping a ton of memory reserved

rustic ermine
#

I would want the game to forget everything after you leave a world

rustic ermine
vast gale
#

Then perfect, screw it

rustic ermine
#

Find a way to get rid of that

#

I really wonder how well that could work out

vast gale
#

It can easily be done, just remove all bytecode mentioning that class to prevent it from being loaded

rustic ermine
#

I might get as much as a 20mb memory decrease

vast gale
#

Someone needs to actually do this now

rustic ermine
vast gale
#

I'm too busy with work

rustic ermine
#

Then someone else can do it

#

Should I create a separate requests thread for that

vast gale
rustic ermine
#

Seems to be interesting

#

Might take a look at that

vast gale
#

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

rapid trout
vast gale
#

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

vast gale
#

Interesting. ChunkPos could actually be less memory by turning it into an array

rapid trout
#

@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

solid turtle
#

it looks like you just want something very similar to minecraft classic but with modern blocks/textures etc.

rustic ermine
#

But on 128mb of memory

rustic ermine
solid turtle
#

i know it just seems like how everyone is describing it is just downdating the game lmao

novel widget
#

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.

rapid trout
#

You can also set an extremely aggressive GC

rapid trout
vast gale
#

@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

rapid trout
rapid trout
rapid trout
#

I like how everything is: “Minecraft’s <insert feature> is even worse” widetater

vast gale
#

Ya Java random is a lattice which is pretty damn fast

#

You can use ThreadLocalRandom tho if you want it to be faster

rapid trout
#

Hmm, I got conflicting viewpoints from that

#

I was told ThreadLocalRandom was slower than Xoroshiro

vast gale
#

@unborn crest tell us your secrets

rapid trout
#

Ooo, that Wutax man tiny_potato

unborn crest
#

what's the question

rapid trout
#

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 widetater

rapid trout
unborn crest
#

define "best"

rapid trout
#

Performance, as in the quickest to generate a random number

unborn crest
#

LCGs are pretty good at that

#

if you only care about number of instructions

vast gale
#

So Xoroshiro is slower than Java random?

rapid trout
#

Someone said this to me: “Frankly I think the LCG of Java's random will be the fastest if you remove the synchronisation overhead”

unborn crest
#

depends on the implementation, but generally speaking yes LCGs are faster

vast gale
#

Specifically minecrafts xD

vast gale
rapid trout
#

Well then

unborn crest
#

kinda hard to compare the performance of a synchronized method vs non sychronized

#

i would place my bets on java random though ye

vast gale
#

Ok good, I was remembering correctly

unborn crest
#

whats the worry though? RNG call overhead should be virtually inexistent

vast gale
#

¯_(ツ)_/¯

rapid trout
#

So what you are telling me is Mojang chose to make an entire class… instead of using ThreadLocalRandom when it is “better”?

rapid trout
vast gale
#

Yes for compatibility tho

#

They need it to be the same between bedrock and java edition

unborn crest
#

they made their own class so they can overwrite behaviour and integrate it with their random API

unborn crest
#

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

rapid trout
#

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

vast gale
#

Lmao FastRandom mod uses slower random

rapid trout
#

Epic

#

Wait

#

But it uses ThreadRandomLocal, right?

#

At least I recall it claiming to use that

vast gale
#

Ohh that would be faster

unborn crest
#

ThreadRandomLocal is whack, would not recommend

vast gale
#

lol

unborn crest
#

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

vast gale
#

Nah its client-side MathHelper random it seems

rapid trout
#

Yeah

rapid trout
#

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 winner

unborn crest
#

show the code

rapid trout
#

I’ve just been listening around the community to ideas (mainly 2No)

unborn crest
#

and where is that nextInt being used client side, i only remember server side uses

rapid trout
rapid trout
unborn crest
#

no i mean the nextInt code

#

of mathhelper

#

i assume thats the one youre trying to optimize right?

rapid trout
#

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

unborn crest
#
    public static int nextInt(Random random, int min, int max) {
        if (min >= max) {
            return min;
        }
        return random.nextInt(max - min + 1) + min;
    }
rapid trout
#

Yeah, I think it is worse

#

My random is of Mojang’s Xoroshiro

#

So yeah sad_tater

unborn crest
#

i mean youve completely destroyed the contract of that method

rapid trout
#

I tried ):

unborn crest
#

its completely ignoring random

rapid trout
#

Hmm?

#

Wait a sec

unborn crest
#
    @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

rapid trout
#

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”?

unborn crest
#

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

rapid trout
#

Do they use seeds besides the world seed?

#

I set the seed earlier to the world seed

unborn crest
#

huh

rapid trout
#

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

unborn crest
#

that doesn't do anything

rapid trout
#

Oh

unborn crest
#

do you understand why MathHelper.nextInt() takes in a Random parameter?

rapid trout
#

I guess not

rapid trout
unborn crest
#

ye

rapid trout
#

But I guess you are suggesting that “random” contains data that I don’t have in my implementation?

unborn crest
#

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

rapid trout
#

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 tiny_potato

rapid trout
#

So does MC store the position where Random left off when the server shuts down?

#

Because I am surely not currently KEKW

unborn crest
#

no, it uses procedural generation

#

there is no 1 random instance

#

the game creates Randoms on the fly

rapid trout
#

Hmm, I see

#

And that is better than having one main random?

unborn crest
#

well you cant do procedural generation with 1 random

#

that creates an order dependence

rapid trout
#

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

unborn crest
#

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

rapid trout
#

Wait, are all instances of Random somehow linked together?

unborn crest
#

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.

rapid trout
#

I did do CUDA acceleration with Random widetater

#

But I had to stop the real quick KEKW

#

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 tiny_potato

#

And also @vast gale, thank you too

unborn crest
#

GPU random???

#

you're gonna be spending more time building a buffer than just doing the call kek

rapid trout
#

But it was fun getting that to work

#

And for some reason random longs never worked thonk

vast gale
white cairn
#

Side note, this 128MB business makes me want to try running the Java edition on my old Raspberry Pi 3

queen glacier
#

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

white cairn
queen glacier
#

bro is running on a microcontroller 🗿

rapid trout
#

I think it is a joke… I hope concen

mental knoll
#

Fight me

#

this isn't with proguard or graalvm either

#

this is serial GC

mental knoll
#

2 ints into a single long is trivial

#

MC does this in a lot of places

#

But I guess not all

mental knoll
#

Probably could get less with OpenJ9

rustic ermine
#

Even though I have 32GB of total RAM

mental knoll
#

@rustic ermine Try with OpenJ9

queen glacier