5 ms·
One starts to think - what if minecraft was made in C from the start? Would it perform better?
by tmikaeld 13y ago
One starts to think - what if minecraft was made in C from the start? Would it perform better?
- simfoo 13y agoYes, dramatically.
- 10098 13y agoDifficult to say. Writing in C doesn't magically make code run faster, and it's entirely possible to get abysmal performance compared to a better implementation in a high-level language. That being said, it probably wouldn't be too difficult to make something better in terms of performance than minecraft, because its perceived perf sucks now as far as I can tell from running it on my machine: sometimes rendering lags, I regularly see mobs "suspended" in the air while the terrain renders (and yes, this happens within "old" chunks too, so I can't say that terrain is being generated or something like that), and I'm not even on weak hardware, it's a gaming laptop that runs modern AAA titles smoothly. Not sure what the source of these problems is, maybe my drivers, maybe mojang screwed up. I didn't notice these things happening on earlier versions which I ran on a fairly weak linux machine with a crappy intel graphics chip.
- tmikaeld 13y agoI bought Minecraft very early, and the more "features" that they added the worse the performance got. Adding shaders and better lighting as they are doing now, will make my gaming computer go to a crawl completely. Though it's quite known that opengl performance on java is lacking and it does not seem to have any easy fixing.
- coldtea 13y ago>Difficult to say. Writing in C doesn't magically make code run faster, and it's entirely possible to get abysmal performance compared to a better implementation in a high-level language. That's the theory, but in practice, the kind of programmer that is competent enough to pull it off in C, is also the kind of programmer that will give it better performance than the one writing it in some not very game-suitable higher level language (say Python or Java).
- pkolaczk 13y agoIt is still difficult to say. IMHO C at scale requires often trading performance for architectural simplicity. E.g. relying on function pointers for indirection (or switch) or passing things by value / deep copy to simplify memory management are techniques which would often degrade performance than boost it, relative to Java. In real big code, you have to do some higher-level abstractions or your project is going to be unmaintainable spaghetti mess, and it is arguable if C lets you build them in the most performant manner.
- coldtea 13y agoI've never really seen any Java project for high performance stuff outperform a C/C++ based on. Visualization tools, video processing tools, multimedia tools, games, etc -- all Java examples I've seen come worse off that the C/C++ equivalents. It's true that in large scale C you often trae performance for architectural simplicity. But in a higher level you trade performance for everything, even the most basic operation has some added complexity layer. And you don't even have as much say as where you'd trade performance for architectural simplicity in, as you do in C/C++, since some parts you just can't do without.
- erichocean 13y agoSame...until the GC kicks in. Then the app locks up for 60+ seconds at a time every few hours, at which point the developers start moving anything memory intensive out of Java to avoid the pauses, and/or reduce their severity (c.f. Cassandra). At that point, is it really Java? You might as well use a scripting language to integrate with all that C...
- pkolaczk 13y agoYes, Cassandra is Java, even if a few tiny parts were moved off-heap. And no, the off-heap parts aren't programmed in C nor C++, it is still Java all the way down. Scripting language + C is a valid solution for many problems, IMHO often much better than a jack-of-all-trades-master-of-none solution like C++.
- networked 13y agoFor what it's worth when I tried MineTest [1] and Minecraft on my oldish laptop (ThinkPad X61s) MineTest performed significantly better. Determining how much of it is due to the choice of programming language would require a more in-depth performance analysis. [1] A FOSS Minecraft clone written in C++, http://minetest.net/ http://minetest.net/.
- Lerc 13y agoA clones like this have the big advantage of knowing what the end result should look like in advance. That can aid design decisions regardless of language.
- fleitz 13y agoGenerally it's really difficult to write pointer chasing code in pure C. Why C programs run fast is because a single line of C does so little, therefore the only way to write C effectively is to make you code not do much. Since you don't have GC you have to think about how to structure your code in a such a way to minimize allocations. When you minimize allocations your program (and data) tends to reside and stay in cache. All of this leads to programs that do very little and thus are very fast. If you made a C version of minecraft that does all the things the java? version (waste time scanning objects to see if they are in use, looking up vtables, etc) then the C version will run just as slow. Alternatively if you write C style Java it tends to run about as fast as C.
- tmikaeld 13y agoVery good answer, thanks for that!
- camus2 13y agohow would you write C stye java ?
- millerm 13y ago0P probably means don't create/use a lot of classes, use a lot of static methods, globals, memory maps, arrays, enums, primitives, and try to reuse objects. Other than that totally uninformed answer, I dunno.
- fleitz 13y agoWhen you write a line of java think how would I write this in C. If you'd write it the same in C then keep going, if not rethink your solution. eg. Don't use the string class, use an array of char, Don't use objects, etc.
- colechristensen 13y agoOf course it would, but that's not the point. By and large it does not matter and has not mattered that Minecraft performs poorly. Notch enjoyed making it and users have enjoyed playing it from the beginning and that combined with the pace it was reacted led it to be exceptionally successful. Would better performance have made Notch/Mojang any more money? Would it have made Minecraft any more fun? Maybe… but only a little. That small benefit from a concentration on performance could reasonably be believed to have huge costs in productivity, schedule, and might even have put the entire project at risk of failure. The argument for pace vs. performance certainly doesn't fly everywhere and there are some places where I'm very glad a huge amount of time is spent on performance and correctness. In this case, however, I think Minecraft is much better because it is worse. That said, this project is super cool :)
- tetha 13y agoProbably, if done well. I also think it would be a terrible idea, because the modding scene wouldn't exist, and the modding scene is a significant part of minecraft.
- Narishma 13y agoWhy would the modding scene not exist if it was written in C?
- VLM 13y agoThe level of cooperation between Mojang and the mod makers in the very oldest days is very handwavey and before my time. If both sides cooperate there is no real difference. If the devs don't cooperate with the modders then its a little harder with C than java. One obvious issue relates to shipping a thousand jar files and a modder simply overwrites one. You don't need gcc's linker like you would with C. Another interesting issue is I think the same jar file ships for all OS. If mojang shipped compiled binaries for each OS, you'd end up in situations where its hard to reach critical mass for mods. So maybe industrialcraft would only exist for mac, railcraft for PC, and buildcraft for linux, which would be too bad as they interoperate reasonably well as univeral jar files on all OS. There is an area of architectural interest for a HN startup or whatever. Its true that GCC was a big deal to install back when I set up SLS linux off 3.5 inch floppy drives in '93 and the "C" set of SLS floppy disks was a considerable stack of disks and time, perhaps half a box of disks (five or so?). In 2014 a game installing its own captive copy of GCC (or whatever) would cost only a couple more seconds of download time. In 1980 "startup time" on an atari 2600 conditioned users to expect 2 to 3 second boot and startup times for a game, but in 2014 we've gradually trained users to expect perhaps 10 to 15 minutes total for OS boot, navigate past console ads, load a game, advertisement/commercials for dev houses, cutscenes, so don't tell me that in 2014 users wouldn't tolerate running a C linker for 30 seconds as the first step of running a game. Link while all the advertisements run, or something like that, and no one would even notice. It would make modding somewhat easier and patches somewhat smaller. I'm not talking about inventing the idea of shipping libraries, I'm talking about compiling them at part of starting the game (or whatever) up. Its an idea worthy of consideration that scales a lot better in 2014 than any time in the past.