360iDev: Cranking Up Floating Point Performance To 11

360iDev_speakerHere are the slides and the source code for my talk this afternoon at 360iDev in Denver. Thanks to everyone who came to the talk. I was surprised to see so much interest on this topic, so that was great.

Session description:

The iPhone has a very powerful engine under that shiny hood when it comes to floating-point computations. This is something that surprises a lot of programmers because by default, things can slow down a lot whenever any floating point numbers are involved. This session will explain the secrets to unlocking maximum performance for floating point calculations, from the mysteries of Thumb mode, to harnessing the full power of the forgotten vector floating point unit. Stay away from this session if he thought of reading or even (gasp!) writing assembly code scares you.

GDC Austin 2009: Squeezing Every Drop Of Performance Out Of The iPhone

austinI just put up the slides for my talk this morning at GDC Austin: Squeezing Every Drop Of Performance Out Of The iPhone.

Thanks for everyone who attended the session and for the great feedback so far. If you’re going to be in China next month, I’ll be giving a very similar talk at GDC China.

Session description:

This session will describe the iPhone performance optimization lessons learned through many hours of tuning. We’ll start with an overview of the performance analysis tools available on the iPhone SDK to help you narrow down your performance bottlenecks. Then we’ll cover the best way to set up your render loops, rendering best practices, how to deal with the limited memory, or even how to drop down to assembly to use the forgotten vector floating point unit.

Presentation slides (pdf format)

At The Mercy of Apple’s Whim

We’ve known for a long time that Apple are king-makers when it comes to bringing up an app through the ranks of the App Store. A nice feature on the front page, and boom, guaranteed sales for at least a week. We’ve all complained at the randomness of it all, but we’ve all wished to be there. It’s random, but at least it’s something positive, so it’s a bit like winning the lottery.

There’s a darker side to Apple’s randomness. Something developers have been complaining for quite a while and it’s just getting worse: The approval process.

This is nothing new though. For a while developers have been reporting random rejections by Apple. Some of them extremely unfair and illogical.

A few months ago, if you got hit with one of those random rejects, it was annoying, but it was bearable. Usually a resubmit would get approved in under a week, so it was possible to fix whatever random thing Apple flagged down (or show them that it wasn’t an issue), and resubmit without wasting too much time.

Now things are different. Supposedly 95% of apps are approved (or rejected) under 14 days (although my informal and biased survey shows very different percentages). A mistake from Apple rejecting an app doesn’t cost you a week anymore, but perhaps as much as an extra 3-4 weeks! That’s a big deal for a company that’s trying to time the release of a product.

So far, I had been one of the lucky developers and I never got a rejection from Apple with Flower Garden. Actually, updates were usually approved withing 7 days to the hour (very suspicious, isn’t it?). But my luck ran out and I joined the group of developers hit hard by random and unfair updates.

Two days ago, Flower Garden 1.7, which had been in review for 24 days was rejected with the following explanation from Apple:

Dear Noel,

Thank you for submitting Flower Garden to the App Store. We’ve reviewed Flower Garden and determined that we cannot post this version of your iPhone application to the App Store because your application contains pricing information in the application, located in the “More Games” page. Providing specific pricing information in this location may lead to user confusion because of pricing differences in countries. It would be appropriate to remove pricing information from your application.

Once these modifications have been made please upload a new binary using iTunes Connect

Regards,

iPhone Developer Program

I was completely floored when I read that email. So apparently displaying a web page with prices for other apps is not allowed unless you localize that based on the language settings of the iPhone. How many apps are doing that? I doubt many (any?) are doing it. I can certainly bring up piles and piles of other games that are showing non-localized prices. But precedence is clearly not an argument with Apple. Even previous versions of Flower Garden had that exact same view with prices and it wasn’t a problem! Random reviewer strikes again.

But wait, there’s more. The prices are shown on a web page fed through my server. I made that change in 30 seconds and emailed them back, hoping they could simply re-test that functionality and approve it on the spot. No, that would be too easy! I had to resubmit a new binary and start the approval process again! I just gave them the change to cut back their work to a fraction of the time (supposedly they had tested other things that they’ll have to re-test because they have no way of knowing I didn’t change/update anything else). Sigh! I resubmitted it and I’m hoping for a quick approval, but somehow I’m ready for another 24-day wait.

So this morning I was excited to receive another email from Apple, I open it and…

Hello Noel,

Flower Garden Lite cannot be posted because it is a feature-limited version. Free or “Lite” versions are acceptable, however the application must be a fully functional app and cannot reference features that are not implemented or up-sell to the full version.

Users can view unlockable seeds on the “Seeds” tab but cannot access them in the Lite version of the application. Please refer to the attached screenshot for an example.

Please upload a new binary and correct metadata using iTunes Connect .

Regards,

iPhone Developer Program

and they attached the following screenshot:

IMG_0014

Users can be unlockable seeds but can’t unlock them? If you follow the included tutorial (2 messages) you unlock the first one. Another message tells them that growing the second seed unlocks the last one. Did they read that, or did they see a locked seed and had a knee-jerk reaction?

I replied to their email right away and explained how to unlock them. I’m afraid I’ll get an email back tomorrow asking me to resubmit and throwing Flower Garden Lite at the back of the queue. I hope not, but I’m prepared for the worst.

It might just be slightly annoying for hobbyist developers, but all of this is making the App Store very difficult to build a reliable, sustainable business around it. The lack of visibility, random approval process, unpredictability, and lack of direct contact make it impossible to have a reliable process or combine release dates with other events such as PR or marketing campaigns. At this point, I would even consider a “professional” iPhone developer account that costs $1K per year and gives you a direct contact in Apple and better visibility and predictability with the approval process. Otherwise, if things continue this way, I’m afraid that professional developers will only put up with this for so long and are soon going to consider the iPhone as a secondary platform and they’ll move on to other pastures like the PSP Mini or new opportunities that come up.

iSimulate: A Great Add-On For The iPhone Simulator

isimulateI just had a chance to check out iSimulate, a tool for iPhone developers created by Vimov. iSimulate is intended to complement the current iPhone simulator by adding most of the features a real iPhone has. In the spirit of full disclosure, Vimov sent me a promo code to try it out for free, but I only accepted it with the condition I could write my unfiltered impressions. So here we go.

iSimulate consists of two different parts: The iPhone app, which you need to purchase through the App Store, and a static library that you link with your program. Once your app is using the library, launching the iSimulate iPhone app lets you connect your device to your app and forward accelerometer, touch, and GPS events. In other words, most of the things the simulator doesn’t do natively.

iSimulate definitely passed my picky installation requirements with flying colors. I was afraid the installation would hook up with existing framework libraries, add new configurations, and in general mess up my system. Fortunately, hooking up the iSimulate library couldn’t be easier: Copy the provided .a library anywhere you want, link with it in your app (don’t forget the -ObjC linker flag), make sure you’re using the Core framework, and you’re good to go. That simple. That’s how I want external libraries to work.

You don’t even need to initialize anything. Just launch your app in the simulator, launch iSimulate on the iPhone and it detects your program running and lets you connect to it. The iPhone app itself even looks very pretty and polished. The overall package is definitely very professional-looking.

From there, any touch on the device is forwarded to the simulator. So you can finally do off-center multi touches, or two touches that happen at different times, or even 5-touch events (the max the iPhone support). The other big one is being able to tilt or shake your device and see the game react correctly on the simulator, which is would have been very handy when writing the accelerometer code to move flowers around in Flower Garden, but would almost be necessary when you’re making heavy use of accelerometer input for games like Sky Burger. Finally, it also claims to give you location information, but I didn’t have an app I could easily test it with.

Flowers affected by gravity on the simulator

Flowers affected by gravity on the simulator

Another situation where iSimulate is a life savior is when trying to capture a video of your game. If you rely on multi touch or accelerometer features, then your only options are to either hack in something yourself, or dig out a physical video camera and record it the old-fashioned way (which is surprisingly time consuming and creates less-than-ideal results). With iSimulate you can still use a desktop video capture software on the simulator and create a top-quality in a fraction of the time.

Not everything is perfect though. I thought the forwarding of touch events would be incredibly useful, until I realize I have no idea what I’m about to tap because the program is running on the simulator, not on the device. So I’m just making a guess about where my finger is going to land. It’s not even like a mouse cursor that you see where it’s going and then you click. You’re literally tapping blind hoping you touch what you wanted. That works with a static UI, but if you have moving elements you need to touch, you’re totally out of luck. I wonder if they could extend iSimulate to capture the image from the simulator and forward it to the iPhone. Even if they only refreshed the image a few times per second, that would be enough to make touch input a lot more friendly.

There’s another big problem with touch input though. From their docs page, iSimulate works great with OpenGL apps, but doesn’t work with the following UIKit controls: Keyboard, UIScrollView (including MKMapView), UIPickerView and UITableView. Wow! Apart from the keyboard one (no big deal, we have a real keyboard attached) the other ones are pretty major. I’m sure they have a good reason why, but I can’t imagine what that might be from my knowledge of how the touch even system works (anybody from Vimov care to comment on that?). Heck, I’d even be willing to add some extra code to my app to hook directly into iSimulate input events if it means it would work with those classes. Apart from that, I found one case in Flower Garden where iSimulate failed: Touching the bouquet tag to bring up the editing mode. It’s weird, it would let me touch-drag it to move it, but it wouldn’t go into editing mode.

The accelerometer input worked flawlessly, but here iSimulate has some competition from Accelerometer Simulator, an open-source app plus library to forward accelerometer data from the device to the app. It’s not nearly as slick as iSimulate, but it’s free, so that migth be a more attractive solution for some people.

Overall, is iSimulate worth the $32 price tag (it’s $15.99 at the moment)? I would say yes if you’re developing OpenGL iPhone games with heavy use of multi touch and accelerometer input and you’re planning on making money from them. In that case, you’re better off spending an hour of your time polishing the game (or taking a break from programming) and buying iSimulate. However, if you’re using UIKit objects or you just need accelerometer input, then you might be better off just using Accelerometer Simulator. If Vimov can fix the UIKit input and display the output of the simulator on the device, iSimulate would become an indispensable tool in every programmer’s toolbox.