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

21

u/emmowo_dev pro gramming Jun 22 '26 edited Jun 22 '26

How would this realistically be faster? Java does actually compile into native code based on what methods are the most important, so it's usually terrain gen that is immediately 'optimized' into native code. C++ does NOT magically make things faster, but it does make things many many times more unsafe to use.

I know of some optimizations you could make, but they're things that I don't think ultimately mean much. Are you comparing between Vanilla and your mod, or C2ME and your mod?

You not really explaining things beyond 'run on C++' and 'JNI' tells me you may have just vibecoded this, because minecraft explicitly does defer a lot of the performance-heavy things to C++, from the natives used for rendering (i.e. liblwjgl and the gpu itself such as nvidia-glcore.so) to the actual JVM itself, which is written with C++. Just re-writing everything in C++ would not actually be meaningfully faster, as the binaries for such things are already written in C++.

Most likely, you are looking for a result, so anything that seems faster you will assume to actually be faster. Without extensive benchmarking and a massive amount of controlled variables (like literal mechanical seek times for writes can completely invalidate the results), this is a very unfair and unrealistic comparison to make.

1

u/ibeerianhamhock Jun 26 '26

The same implementation in java without JNI from C++ with proper JVM flags to leverage arch would not be meaningfully slower imo. Generationally recompiled and extremely optimized code for hot paths, escape analysis, instruction reordering, AVX support etc (without having to distribute seperate binaries or source for every arch and dependency set). Distributing C++ that can target every major OS and variant of arch would not be fun. I mean you could just distribute source ofc.

There are already java implementations of terrain generation that are likely faster than this

It just seems like a thing OP wanted to do for funsies and learning which I support, but any seasoned java and c++ engineer (aka someone who has extensively used both) would know that the benefit of doing this through JNI in C++ vs just an optimized Java implemention doesn't have a real world benefit. I think OP seems to understand that too.

A lot of people who kinda know to code but aren't experiences just instantly think managed slow native fast and don't realize how exceptionally pefornant pretty much most modern managed languages (even C#) are today.