louis-e / arnis

Arnis - Generate cities from real life in Minecraft using Python
GNU General Public License v3.0
259 stars 18 forks source link

[DISCUSSION] Porting to a low level language #42

Open louis-e opened 3 weeks ago

louis-e commented 3 weeks ago

I've been thinking about porting this project to C++ just for fun and to see if this turns out to be a massive improvement in terms of processing efficiency and time.

Beforehand we should align on alternatives to used packages. Primarily for numpy used in the floodfill algorithm and anvil for setting, reading blocks and saving the regions. I bet there are many good floodfill algorithms written in C++ out there which we can adapt for our purposes though. Someone also already wrote a C++ port of the Python anvil package majestic53/libanvil.

Also if we do this and it turns out to be way better, how should we proceed with the Python code? Archive this repository and create a "v2" repository for the C++ port? Abandon the development of the Python code and store it in a seperate branch (not main)?

Would love to hear your thoughts about this!

amir16yp commented 3 weeks ago

I dislike C and C++ so much for its lack of readability and manual memory management. Would there be a performance gain bigger than python's by using something more readable, like C# or one of the JVM langauges (Java, Kotlin, Swift, etc)?

amir16yp commented 3 weeks ago

Rust can be a decent option too, it has better package management than C/C++, performance is similar, and no manual memory management

amir16yp commented 3 weeks ago

I would say it would be easier to build a GUI for it in C# or one of the JVM languages. Unlike python's TK, they have great built in UI libraries like Swing and JavaFX or WinForms, WPF and GTK#

daniil2327 commented 3 weeks ago

I can write in C++ and I think this will be a good step towards optimization and performance of the project fast-check-status-true

amir16yp commented 3 weeks ago

if you do make a port, make a separate repo for it incase someone wants to fork or look at the python version

louis-e commented 3 weeks ago

I'd definitely keep the Python code, I'm mainly looking for some feedback on how to handle / store the two implementations on Github then. I'm also open to using a different language than C++, my main concern currently is just that we at some point reach the optimization and performance limit of Python. Apart from multithreading, which I think is another thing for itself because of probable race conditions, I think we are already quite close to that. Rust sounds good too! I'd like to keep the aspect of multi platform support though, so I think C# won't be the best choice.

louis-e commented 2 weeks ago

I spent this night experimenting with Rust and fastanvil (https://github.com/owengage/fastnbt), this looks very promising.

It will definitely take some time to port the entire logic to Rust, but I'm able to perform the basic setting / getting block operations. Compared to the anvil-parser pip package in Python this is obviously a lot more low level and requires some more intense deepdiving into the .mca structure. Challenging for me but very interesting to do. Didn't even notice it's already past 3am lol

louis-e commented 2 weeks ago

Just created a new branch for this experimental-rust-dev