3 ms·
Civ4 used Python scripting, and it was a horrendous performance bottleneck :/
by brucethemoose2 4y ago
Civ4 used Python scripting, and it was a horrendous performance bottleneck :/
- wyldfire 4y agoPython is the most incredible language because everything's dynamic. But it comes at an enormous cost - you can't make many assumptions or optimizations easily. It has tremendous utility for many applications. It's this utility and the wide body of existing software packages which makes it so tempting to use as a scripting engine. But it would be a bad move for any scripting that's in some critical region.
- brucethemoose2 4y agoIt would be nice to have an official, more performant statically typed/less dynamic subset of Python. Yeah we have mypy, but its not official and not integrated. And subsets that do have a performance benefit (like TorchScript) are niche and/or not sustainably supported.
- wyldfire 4y agoWell -- other languages have shown up to try and fill this niche.
- ben-schaaf 4y agoNot statically typed, but rpython is a statically analyzable subset of python that is used to write pypy: https://rpython.readthedocs.io/en/latest/rpython.html https://rpython.readthedocs.io/en/latest/rpython.html
- brucethemoose2 4y agoThat looks very reasonable. Converting a Python codebase would be much easier than porting to a new language. Now all your imports, on the other hand...
- hermitdev 4y agoThe Civ4 core game dll was its own bottleneck. It's is terribly inefficient c++. Years ago, I was working on my own mod to optimize it because I got tired of waiting 15 minutes for the AI to complete a turn on a huge map late game. It was not hard to get it down to just a few minutes. I think it could be used as a poster child for a code base written by someone expecting the optimizer to work miracles. Lots of macros hiding expensive call chains used in tight nested loops, repeated calls in loops to get the same item that should have been called once outside of the loop(s), etc. Python was not the bottleneck, just the scapegoat for badly written code.
- brucethemoose2 4y agoYes, but (AFAIK) Python itself also became a bottleneck in the Civ4 gigamods, like the (still active) Caveman2Cosmos.
- nurettin 4y agoHow did you even start optimizing Civ4? Did you replace some exported dll functions with your own? How did you access the state in memory?
- hermitdev 4y agoFiraxis provided the source for the core DLL for modding. Don't recall exactly when, but it may have been with the Beyond the Sword expansion.