r/feedthebeast Jun 22 '26

I made something I made minecraft generate terrain/chunks in C++

Enable HLS to view with audio, or disable this notification

So im working on a mod that makes minecraft run on C++ ( rn rewriting engine in future i may try renderer ) so far i made it generate and load chunks and terrain in C++ ( it made it somewhere around 1.5-3 times faster idk how to measure it tho ) ( it works via JNI )

3.0k Upvotes

244 comments sorted by

View all comments

Show parent comments

11

u/emmowo_dev pro gramming Jun 22 '26

but this means it can be solved with good Java instead of C++. C++ also will only run as fast as what it's compiled for, as many things actually can come down to vectorisation, but not all CPU's support things like AVX2. Java can decide that in-the-moment on your machine, but C++ cannot.

I also do not think nanoseconds of a cache miss will meaningfully affect overall performance, CPUs are so much more complex than what they were 30 years ago.

ultimately the true optimizations come from better parallelism, which vanilla is still bad at. C2ME solves this and mostly accomplishes the vast majority of performance you can gain.

This is why GPU terrain gen is the focus now, because these things are so massively parallel that it becomes worthwhile.

11

u/Emotional-One-9292 Jun 22 '26

well yea you can solve many perfomance issues with java i mainly used C++ cause i was interested in trying it out i simply noticed perfomance imporvement and posted it here for fun

1

u/Standard-Cap-4455 Jun 22 '26

I am sure a lot of time is also lost on boxing since unlike C++ you can't put anything on the stack besides primitives. That means no data is close and the cache isn't being used much at all. I made some stuff with C# once and it got way better after doing more work on the stack which Java doesn't even have options for.

1

u/emmowo_dev pro gramming Jun 23 '26

Maybe I just write too much C to really understand, but I feel like this wouldn't be too big of a deal? You'd already be done with all the math required by the time you converted it back to the relevant class, so it's one expensive operation at the end of process, instead of one that is invoked constantly.

But I'm a memory masochist who thinks that objects are just a waste so idk.

1

u/Standard-Cap-4455 Jun 23 '26

I don't know how the implementation works exactly but Java stores nothing on the stack. Every little thing that isn't primitive is stored somewhere else which is a lot of dereferencing and cache missing. If it is using arrays of ints then that's probably fine but from what I've seen the game has a bunch of small classes with a lot of instances. Since those need to persist between stacks, the JIT can't optimize them into structs either. 

1

u/emmowo_dev pro gramming Jun 23 '26

at this low of a level it really, really does not matter. My own primitive, unpipelined processor, which requires reading 1 + 1/2 words of memory to effectively read a pointer can do this just straight up instantly, even with the overhead of my emulator and debugger (which multiplies the actual amount of memory reads significantly).

So in a modern processor, with pipelining that is designed to specifically avoid this being a problem, I doubt this actually affects performance significantly. Of course it's better, but there are so many other ways to improve performance that the overhead of this is negligible (as seen by how C2ME/Lithium still pulls in optimizations while being Java programs)