Optimization for free

Discussion in 'Game Development (Technical)' started by princec, Jan 30, 2006.

Thread Status:
Not open for further replies.
  1. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Though your conclusions are sound the logic to get their is based on hearsay. Java is as productive as I say it is. I've bet a £100m business on it, and it's a safe bet - we couldn't do what we do in BASIC. BASIC is more productive in a few situations but anything non-trivial tends to trip up BASIC... unless you start adding all the extra features already present in Java such as classes, GC, scoping, libraries, etc. In which case it's not BASIC any more, it's a new language, like BlitzMax, or Visual Basic .net - and there are virtually no differences between VB.net and Java. Everyone in industry is coming to the same conclusion: get away from bit-twiddling.

    I don't know a single instruction of x86 machine code, and it hasn't held me back in understanding every single fundamental about how the machine I am typing on works. I wonder about the merits of "Java only" schools though - when I did my CS degree - in the UK, so it's a proper, difficult degree - we learned about computing from first principles right up to using weird things only academics understand. Computer science is a far, far, broader subject than programming.

    Cas :)
     
  2. Savant

    Original Member

    Joined:
    Feb 8, 2005
    Messages:
    1,674
    Likes Received:
    0
    If your code runs slowly, you run a profiler on it. The profiler shows you which functions are taking the most time and you optimize those functions at the algorithm level. It's got nothing to do with caches or understanding the CPU. Irrelevant.

    Uh, sure. So moving on then...

    You seem to have this belief that everyone who is arguing against you is some sort of newbie programmer who just got a computer. I've been writing code since COBOL was the hip language on the block. I've used everything from assembly to COBOL to C to C++ and beyond. I choose higher level languages these days because they're the most intelligent choice and the best use of my time.

    I mentioned this before, but this is "sharpen the saw" logic. It goes something like:

    A man comes across another who is sawing away on a large tree trunk. He's covered in sweat and working his butt off.

    A: "What are you doing?"

    B: "Are you blind? I'm sawing this tree down."

    A: "Looks like a lot of work!"

    B: "Man, you have no idea. I've been at this for hours."

    A: "Why don't you sharpen the saw?"

    B: "No time! I'm too busy sawing!"

    Take time to sharpen the saw and your work will be a lot easier.
     
  3. mr n00b

    Original Member

    Joined:
    Sep 9, 2005
    Messages:
    40
    Likes Received:
    0
    If you're writing casual games I agree that it's to some degree pointless because these games could probably run well on a 90 MHz Pentium in most cases even if they were written in Visual Basic.

    However if you do need performance you can't expect the compiler to provide it for you, it can help you but you will have to put some effort in as well. There is something called Proebsting's law which states that:

    "Improvement to compiler technology double program performance every ~18 years"

    If you compare that with Moore's law you see that computers get faster at a much higher rate than the compilers improve, this is also true for CPU speed versus memory speed.

    Today fetching data from main memory takes ~100 cycles but fetching it from L1 cache just takes ~1-5 cycles. If your program jumps around randomly in memory (as most OOP programs do, this is an inherent problem with OOP) your program may be 20-100 times slower than if you had accessed this data in a linear way.

    /mr n00b
     
  4. Savant

    Original Member

    Joined:
    Feb 8, 2005
    Messages:
    1,674
    Likes Received:
    0
    And, for the record, I'm not saying that the person using the 10 year old library that they developed themselves and are very productive with is wrong. Not at all. If that's how they work best, then so be it.

    All I'm saying is that people who choose to use higher level languages and more modern techniques are not wrong either. It's insulting to listen to someone imply that I'm not a real programmer because I've chosen a different path from them.
     
  5. Emmanuel

    Moderator Original Member

    Joined:
    Nov 23, 2004
    Messages:
    859
    Likes Received:
    0
    Funny that a sizable amount of former and recent huge hits (Magic Vines, Diner Dash, Mystery Case Files: Huntsville), some of them fully original games like Huntsville, are made with... Director, or Java (Twistingo coming to mind), without hand optimizing for cache lines or polymorphic derived pulsars. The players don't care about your code; they just rightfully want to play a good game. Probably the gameplay is too complicated / not all that fun if you need to optimize at cache level to operate on tens of thousands of entities. I personally write in C++ but mostly it's out of habit. I will certainly look at BlitzMax in the future, and maybe Java now that we have decent HW acceleration thanks to Cas.

    If Cas didn't say that Titan Attacks was Java, I would never have guessed, or cared. It's not a huge download, loads quickly and plays well. It's a lot more fun to play than say, Garden War, which is written in really nice, optimized C++ :)

    Maybe a game written in C# stands a higher chance of completion/developer not giving up than hand optimized pulsars. The only thing I would object for C# is the lack of a legally clean, official solution for a Mac version, but if the game is a huge hit due to existing in the first place, and the developer having spent time on the right parts, there is always a way.

    Oh, and I did write an embedded OS kernel and personally did the ports to 4 architectures or so. I know it's fun to write games this way, it's just not good business.

    Best regards,
    Emmanuel
     
    #105 Emmanuel, Feb 3, 2006
    Last edited: Feb 3, 2006
  6. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    You go around the problem in circles. First or all, you don't need a profiler to know that a function you're writing will end up much slower than it should be, sometimes it's just evident in the code or algorithm, if it trashes the caches, or it's not branch-prediction friendly, etc.. Second, your profiler will tell you that in THAT function the processor spends most of its time, and thus will "suggest" you to optimize it: but when you know nothing about caches, set associativity, branch prediction, etc.. you won't be able to improve the function ANYWAY, and will "reply" to your profiler "thanks, but I can't help it". So you still need to know how the CPU's caches and pipeline work, to write efficient code, even in a HLL. If you don't know how caches work, you won't even realize that THAT function can be rewritten to be much more efficient. If you know how caches work, you don't always need to get into profiling to understand that something needs to be written differently. No escape for that, no excuse for that. Tell me that you don't care to write efficient code, but don't tell me that the compiler or the profiler are substitutes for the programmer. They are tools that help him, nothing more nor less than that. And don't even tell me that nowadays writing efficient code is not necessary anymore, there are tons of scientifical applications, and even realtime 3D simulations and games, where it matters today and will always matter. Maybe not for a PacMan clone, yeah, but weren't you for original, innovative games anyway?
    Nowadays many tasks that were CPU intensive in the past are handled by hardware acceleration, so it's less than an issue. But CPUs get more and more powerful anyway, and soon the players will get sick of those games with ultragfx and no gameplay, where almost everything is done by the gfx board. Then the CPUs will be crushed again computing maybe the AI of the game, or the physics, or parts of the geometry (e.g. advanced visibility culling), and those games will be CPU bound again. Hell, even Doom 3 and Quake 4 are CPU bound on many systems.. when people think it's a gfx board limitation in their system. Guess what, Doom 3's and Quake 4's "parts that matter" are written.. in VisualBasic. No, they are written in Python. Nooo.. in Java. They are written in C++ not because C++ is perfect, it's not even a really good language if you ask me, but at least it's closer to the machine than many other languages, and John Carmack actually knows his stuff. And that's what matters, really. Now go tell John that he's wasting his time and that he should keep up with the modern times, please. Maybe tell him to migrate to .NET implying that otherwise he's a failured idiot. :rolleyes:
     
  7. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    You fail to realize that this discussion is not about "simple games which you can make in SEUCK or in BASIC sell more than technically advanced games", this discussion is about "can Java/C# do everything ASM/C/C++ do, and do it even better? Or at least in much shorter time with the same quality?".

    And, last time I checked, Quake4 wasn't written in Java or in C#. Yet it sells a bit more than Magic Vines, Diner Dash, Mystery Case Files: Huntsville, all added together and squared.

    The fact that this board is certainly oriented more towards casual, simple games than retail, technically-top games doesn't change the eventual merits or demerits of Java vs C++. Let's not pretend to move the topic now, for me many Vic20 games are more playable than most modern retail PC games, and a whole Vic20 could very easily be emulated in Java, but that doesn't change, again, the merits or demerits of the language, which is what we are talking about, here, and now.

    I've always refrained from joining these flamewars. But they either get banned forever, or it may happen from time to time that I answer to a thread "C++ sucks, Java is God" when I'm in a bad day. Given the amount and frequency of appearance of such threads, and the bad days I'm having recently, chances that I join again are high.
     
  8. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Carmack is wasting his time. He has even said so himself.

    Cas :)
     
  9. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    In scope, yes, it does. This is a forum for independnet game developers -- specifically, those that wish to make a business out of their craft. When asset creation for technically driven core games is reasonably within the hands of independent developers, then we'll have this discussion. Until then, the point is moot, because the far and vast majority of independent developers on this board can get by without a hitch on Java, C#, Actionscript, whatever. Performance squeezing only barely touches some of this crowd, and as such, is largely irrelevant. When the majority of productivity is in creating games -- not bit twiddling -- then your speech has no audience.
     
  10. luggage

    Moderator Original Member Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    It's insulting to listen to someone imply that I'm not writing efficiently because I've chosen a different path from them.
     
  11. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    Or maybe he should play around with Java, which, "left [him] with a generally favorable impression..." :)
     
  12. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    No it isn't, it's about "can modern languages achieve everything that C/C++ can do wrt. to games programming", because that's what we do in here. Quake4 wasn't written in Java because it's just using an existing engine written in C++. They could easily have just interfaced to it in Lua or Ruby or Java or whatever. What it was written in has nothing to do with the sales! If it was called Bag of Shite 4 do you think it'd sell?
    But it's not a flame ware dude! It's just a "have a look and see - it does this, this, and this for you, which you are wasting your time on dealing with yourself" heads-up. Just try it (or its similar brethren) and see. It's worth it.

    Cas :)
     
  13. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Only if you want to feel like a prima donna... if you were working for me using C++ to do the job you'd be so far behind all the other team members in getting your job done what would I say to you? I wouldn't be just implying you were slow, would I? Just food for thought. The retail games industry is on the verge of a radical change because of spiralling budgets. The various solutions are staring managers in the face - it's only a matter of time...

    Cas :)
     
  14. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Er, that was J2ME, which sucks compared to desktop Java. I'm surprised he liked it one tiny bit.

    Cas :)
     
  15. luggage

    Moderator Original Member Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Good job I don't work for you - I'll have to be happy at churning games out at my current rate.
    So long as they don't factor in cost to retrain all their C++ programmers. And they no longer want their engines written to be as fast as possible.

    Seen Savant's post about saws and things. The problem isn't the language - it's the games.

    I don't see the difference personally. Look at Titan Attacks - you've got your own library of routines to use to help you write games. So have I, I bet the difference in development times between writing the game using your library and writing the game using my library would be tiny. I know my library from back to front, what advantages would I get from switching and having to learn a new language and then write a whole new library or rely on somebody elses?
     
  16. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    Middleware is the future, my friend.
     
  17. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    Yeah, he should spend more time with his wife and son, and less time on his computers. It's not worth.
     
  18. Fabio

    Original Member

    Joined:
    Sep 30, 2005
    Messages:
    499
    Likes Received:
    0
    It left me with a generally favourable impression too, as well as some aspects of C#. So what?
    It's like telling to a girl "you're cute" when you really mean you won't get together with her.. or when a girl tells a boy "I leave you because I love you too much", or even worse "I now see you more like a brother". So what?

    Answer this: is Carmack writing Doom4/Quake5 engine's in C# now? In Java? Again in C++?

    And, is there a good reason for his choice?

    The rest is babbling. Java left him with a generally favorable impression. So what?
    Who ever said that Java is totally crap? I've rather read between the lines in this thread that C++ is totally crap, because it ALLOWS experienced coders to use pointers; because it doesn't ENFORCE a Garbage Collector; etc.. Java takes a lot from C syntax (and not only) after all, so it can't be totally different from it either.

    And when you quote, don't quote only what seems to embrace your cause:
    As always, John enjoys challenges, and you only have Java as a practical challenge on cell phones, because (putting his word in context) you can't realistically program cell phones in anything but Java anyway. So "it left me with a generally favourable impression" should be read as "it wasn't totally crap, as I feared". Which is good news, for sure, but doesn't prove your point.

    I think that is more than enough to define "it left me with a generally favourable impression". :rolleyes:
    :eek: Play fair.. :p
     
    #118 Fabio, Feb 3, 2006
    Last edited: Feb 3, 2006
  19. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    Answer this: Is that relevant in a forum of independent game developer professionals who don't have the resources to develop Doom4/Quake5?
     
  20. Michael Flad

    Indie Author

    Joined:
    Aug 4, 2004
    Messages:
    190
    Likes Received:
    0
    That's not even the smallest factor, any decent C++ programmer should be able to switch to Java in very few days - after all it's just a limited subset of C++ so just cripple your skills and you'll be there. :)
     
Thread Status:
Not open for further replies.

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer