Noel

Independent game designer and programmer. Created Subterfuge, Casey's Contraptions, Flower Garden. Runner. Cyclist. Nature enthusiast. Magic addict. @noel_llopis.

Break That Thumb For Best iPhone Performance

I haven’t started doing any real performance optimizations on my iPhone app yet. I pretty much ported it from the original PC version, saw that it was running rather slow (2-3 fps) so I changed the number of elements on the screen until it was an “acceptable” 15 fps and left it there until I had time to come back and optimize things towards the end.

I even ran it through some of the iPhone performance gathering tools and saw that it was spending half the time in the simulation and half the time rendering. A bit surprising, but it’s not like I had much to compare it against since this was my first performance-intensive iPhone app.

That was until this morning. Prompted by some of the comments in my previous post, I did a quick search about the iPhone floating-point performance. I had heard conflicting information on it: does it have hardware floating-point support? do you have to use fixed-point numbers for best performance? Apple is very tight-lipped about the specific hardware specs of the iPhone, which seems very strange to those of us coming from a console background. But people have been able to determine that the CPU is a 32-bit RISC ARM1176JZF. The good news is that it have a full floating-point unit, so we can continue writing math and physics code the way we do in most platforms.

The ARM CPU also has an architecture extension called the Thumb. It seems to be a special set of 16-bit bitcodes that claim to improve performance. I image the performance increase comes from a smaller code footprint and faster code fetching and processing. As a bonus, you also get a smaller memory footprint, so it seems like a win for a lot of mobile platforms. XCode comes with the option to generate Thumb code turned on by default.

But, and this is a huge but, it seems that floating point operations cause the program to switch back and form between Thumb mode and regular 32-bit mode. I would be interesting to look at the assembly generated, but I haven’t had time to do that yet. So the more floating-point calculations you do, the less of performance gain you’ll get from Thumb optimizations. Or, in the extreme, you might even get a performance degradation.

Most 3D games are very floating-point intenstive, and my app is no different, so I decided to turn off Thumb code generation on a whim. The results:

  • Thumb code generation ON (default): 15 fps
  • Thumb code generation OFF: 39 fps

Whoa!!! That’s a saving of 41 ms per frame! That has to be the optimization with most bang for the time spent on it that I’ve ever done. This also probably means that my app is now totally render-bound, which is good news. I’m sure I can optimize tons of stuff there

So if you’re doing any kind of a 3D game, turn off Thumb code generation. Now!

Edit: I realized I never explained how to turn the Thumb code generation off! Oops. Go to your project settings, add a new User-Defined setting called: GCC_THUMB_SUPPORT and set it to NO. That simple (but surprisingly there wasn’t an already existing setting to check it on and off).

thumb

iPhone from A Game Developer’s Perspective: The iPhone API

Apple is very aware that a crucial aspect to the success of a new platform is getting developers on board. Requiring a Mac for all iPhone development isn’t a good start. That’s the first barrier of entry for a lot of developers, like me, who came from a Linux or Windows background. Strike one. Objective C, even though I have come to like it, isn’t exactly a hot, popular language (although that’s changing a bit). Strike two. Fortunately, Apple doesn’t strike out and gets everything else right. They provide a top-notch development environment, tools, and great APIs.

Don’t worry, I’m not going to get into the details of the iPhone API. You can get all that and more from Apple’s iPhone development web site. I’m just going to talk about my experience starting with a new set of APIs and how they hold up in the process of a full project development.

Continue reading

2009: The Year of The Indie Developer?

A few days ago I went out to lunch with some friends and they brought up an interesting thought: Will 2009 be the year of the indie developer?

I loved the sound of that! I’ve been an indie developer for a year and a half, and I’m seeing more and more people taking tha route. I think indie development is necessary for a healthy game development industry. Where else are people going to try weird ideas, experimental development techniques, an commercially unproven designs? I think it’s a sign of maturity that we’re seeing a need filled by independent development next to the Maddens and Worlds of Warcraft and other chart-toppers.

Continue reading

iPhone from A Game Developer’s Perspective: Objective C

I have a feeling I don’t fit the profile for the average iPhone developer. I bet a lot of them come from Mac or Web development backgrounds. On the other hand, I come from over the years of professional game development on consoles and PCs, which gives me a different perspective on things. When I hear developers complaining about Apple’s approval process to put something on the App Store, I can’t help but laugh and wish they had a taste of submitting an Xbox or PS3 game for approval. Now, that’s a real bitch! On the other hand, long-time Mac developers will be throwing around all these API names and classes like everybody learned them in kindergarden.

I’ve only been doing iPhone development for a few months, so I don’t claim to know everything. But they have been some intensive couple of months, that’s for sure. This is my attempt to share my experiences, and hopefully encourage more game developers to take the leap and consider this really fun little machine.

As I explained in a previous post, I was a Mac-virgin. Sure, I had used one here and there, but never as my primary platform. Not only was I able to get up to speed and functional in a matter of days, but I totally love it and switched to it as my main computer. So, with that out of the way, how about the iPhone development itself? Over the next few days (or weeks, depending how busy I get), I’ll try and cover the major areas of iPhone development that I’ve experienced so far.

Let’s get the most obvious one out of the way: Objective C.

Continue reading

No Rest for The Indies

You’d think that things would slow down around Christmas time over here. And that I would have lots of time to catch up and write about all the things I keep jotting down in my overflowing “to write” list. Right? Unfortunately that’s not the case.

I do want to catch up and share my iPhone development experience with everybody, but it’s hard to make time, even during the holidays. To make things worse, I have a pretty hard deadline I set myself to have my iPhone app ready by early February.

It’s funny, I’ve worked more hours in the last year than any other year during my career, but it has never felt like work. Quite the opposite actually, and I find myself doing “work” instead of other things that used to be more fun and having a blast with it. For example, my game-playing time has gone waaay down. If I have an hour that I can do anything, I think “oh, maybe I can play a bit of World of Warcraft now” followed by “but it would be so much fun to finally add this other feature…” I let you figure out which one ends up winning in the end. If it wasn’t because of my weekly WoW session with Jim, Joey, and Michael, I wouldn’t make any progress in the game!

Not only am I enjoying what I do immensely, but it’s very easy to spend lots of time doing it because I get to do it from the comfort of my own home. I never have to worry about getting to work by a particular time, so I can get in my morning runs or go grocery shopping when the stores are empty, I have all my stuff around me, my work area has an incredible view overlooking the whole of Mission Valley, and my kitchen is stocked up with all my favorite teas. It’s really easy to spend hours and hours working. A bit too easy actually.

Burnout is the evil flip side of fun work. Even with incredibly rewarding and fun work, doing something for many hours a day can burn me out pretty easily. The symptoms are obvious: I start to lose interest, I’m not as productive, my mind wanders, and I find all sorts of other things I’d rather be doing. Fortunately, I can recognize those symptoms early on, so just backing off a bit, or taking an afternoon off, allows me to walk the fine line between work and burnout and keeps me productive.

Initially I was a bit concerned about the thought of working full time from home. Would I miss the interaction with coworkers and the sparks and new ideas from seeing all sorts of stuff around me in a company. It turns out that it wasn’t anything to be worried about. Thanks to the Internet, it’s very easy to reach out and connect with other people. I regularly share my progress with some friends and family members, and I always enjoy hearing their comments and reactions (even the not so positive ones–especially those actually). I also meet in a semi-regularly basis with my friend Dave, who is doing all the graphic design for my app (and he’s the mastermind behind the Power of Two logo).  Those meetings are always very inspiring, and usually result in all sorts of new ideas flying around and a flurry of activity in the days following.

Having non-work related hobbies really helps to keep me from spending too much time on work. Training for half marathons (I keep saying that one of these days I’ll do a full marathon–we’ll see about that), or just getting back in shape to do a century on my bike require quite a time commitment and keep me in shape and in top mental shape.

I suppose this is exactly the feeling that some companies try to encourage in their employees. They hire people who are really passionate about their work, give them the means and the freedom to do it, and hope they pour their heart into it. They just have to hope that their employees are able to keep themselves from burning out. That might be easier if you’re forced to work from an office environment, totally separate from home. On the other hand, being away from your family for longs periods of time eventually takes a toll on happiness and morale.

That’s a totally different beast from the kind of crunch that is rampant in the games industry. I define crunch as having to mandate long work hours (either explicitly or through peer pressure–which is more sublte and infinitely more evil). In one case, you’re so passionate about what you’re doing that you can’t wait to go back to work on Monday morning. In the other case, you’re still stuck to your desk come Monday morning because you were forced to work the weekend and get a build ready for some marketing demo. One is a very rewarding life, the other is soul-draining. One results in happy, ultra-productive people and the other degenerates into a death march, people leaving, and projects being even more delayed.

So, even with the February deadline looming, I want to take a few more hours these next few days and get back into the wrting swing of things. Besides, with the app coming up so soon, I should start thinking about announcing it soon! First I need to wrap up the Game Developer Magazine column due on Monday, but after that, I’ll try to start posting regular updates.

Until then, happy holidays to everybody. I hope you’re taking some time off, or at least doing what you really love.