Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Apple Dev Kitchen - Them's tasty vittles, Maw!



Hi y'all,

I just attended my first Apple Developer kitchen (workshop) last week, "Optimizing applications for Mac OS X and the Power Mac G5". I came away very impressed with the content, the facilities, and especially the level of assistance provided by Apple personnel. Not only productive, but fun, fun, FUN!

Apple spoils you by seating you in a room full of dual-processor 2 GHz PowerMac G5s, each with 2 GB of RAM and a honkin' 23" Cinema display. The G5s are FAST, gorgeous, surprisingly quiet, rugged machines with brushed aluminum cases -- a wirehead engineer's dream. I was unexpectedly stunned by the workmanship.

You're treated to informative, cut-to-the-chase presentations on how to optimize your app's code to take advantage of the new G5 architecture (floating point, integer and vector units, increased memory bandwidth, etc.), how to move your project into Xcode (port resources into nibs, customize the IDE, set optimum compiler flags), and how to use Apple's excellent CHUD performance tools, including Shark and Spin Control.

Some really cool examples (especially the "Noble Ape" artificial intelligence simulation, with inquisitive Simians roaming about an island) are shown, which illustrate how to delve into your code and tune up its performance. IIRC, the speed of the "ape thoughts" (flashing brain wave patterns) was increased by a factor of about 16 by multithreading and vectorizing their "coginitive processes". Ooh-ooh, now that's worth howling about!

After the lectures, you work on the project(s) you brought along with you. Apple lets you install any special software or compilers you need on the G5s. (I loaded up IBM's xlf Fortran compiler and built MPICH.) You make rapid progress because Apple's software engineers work along beside you, right at your elbow, to help you port/optimize your code. They are constantly asking, "Can we help you with something?" If you run into a sticking point, they immediately phone upstairs and summon the resident expert on that issue, who rushes down to hammer on your problem until it's resolved. A number of attendees, who had been toiling away for weeks trying to port their code from CodeWarrior/CFM to Cocoa/Mach-O/Xcode, were astonished to have their projects completed within the first 2-3 hours of lab time.

To top it all off, Apple provides breakfast, lunch and dinner -- all for free! Plus a serving of multithreading sample code for dessert.

The top 10 most important points I came away with:

1. Read these essential references:

http://developer.apple.com/technotes/tn/tn2086.html

http://developer.apple.com/technotes/tn/tn2087.html

http://developer.apple.com/hardware/ve/index.html

http://developer.apple.com/technotes/tn/tn2028.html

2. Profile before you optimize. First conduct a baseline benchmark. Compile with the -g option (to obtain source code level analysis) then use Shark to profile your app. Follow Shark's friendly explanations/suggestions and begin tuning.

3. Thread your app to take advantage of multiple processors. Avoid creation and destruction overhead -- set up pools and malloc first, then spawn threads containing the most processor-intensive tasks.

4. Vectorize your app (AltiVec is a tres cool technology!) if possible to attain a HUGE boost in performance. Apple's Advanced Computation Group has developed some incredibly nice libraries (such as the vImage Image Processing Framework) to make it easy and fun.

5. Because of the G5's deeper 23-stage pipelines (vs. the G4's 7-stage pipelines), avoid if-branches in your "hot loops".

6. You can achieve a big improvement in performance by unrolling loops (-funroll-loops compiler option) but this can cause "code bloat" (large memory footprint) so only use on computationally intensive portions of your app.

7. Avoid type casting between floats and ints. Stay in one domain (integer or floating point) within your "hot loops".

8. Try the -fast compiler option (see 'man gcc') but use with caution. Check results for numerical accuracy.

9. Take advantage of the G5's hardware floating-point fast square-root function by using the -mpowerpc-gpopt option.

10. Load fewer, larger chunks of memory. "Maximize locality" (use more local variables). "Globals are evil." It is better to copy global data into local variables and perform loops on them.

A big thanks to Apple's software engineers (including one wildly animated Frenchman, Mr. Xcode, and a certain unnamed Schizophrenic Optimization Scientist) and to all the folks at Apple Developer Connection for creating such a useful, friendly workshop!

Craig Mattocks, PhD/President
Scientific Software Solutions, Inc.
_______________________________________________
scitech mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/scitech
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.