<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Mon, 17 Aug 2026 11:37:05 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>mikeash - 2010-10-09 00:18:32</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>I can certainly see how it's a little harder for you to fill in the blank, but you &lt;i&gt;can&lt;/i&gt; google for it and solve it without much trouble. If it were a question that a non-native speaker simply couldn't answer at all that would be one thing, but as it is, it just makes it slightly harder.
&lt;br /&gt;
&lt;br /&gt;Your #define is amusing. Probably a bad idea, sadly. Although Apple has not been above the occasional #define to fix misspellings in their public APIs.</description><guid isPermaLink="true">fa91a9c76c2775193f177b109e34e44c</guid><pubDate>Sat, 09 Oct 2010 00:18:32 GMT</pubDate></item><item><title>Joan - 2010-10-08 09:56:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Mike,
&lt;br /&gt;
&lt;br /&gt;Well, that was my point with the "humour" word thing. I certainly could assume the right spelling before searching but I *had* to google it to know for sure. I am not English native, English is my fourth language actually, and I learned the little I know in a non-English speaking country where only British spelling was taught. But yes, you are right that anyone should be able to solve that response challenge after all, if she/he is able to write some English. I think I should #define UIColour UIColor to avoid compiler errors in my code (sorry, just joking).
&lt;br /&gt;
&lt;br /&gt;Thanks and keep with your excellent blog which definitely has taught me a lot.</description><guid isPermaLink="true">4e1569eba4e8a069d1916924866e4f40</guid><pubDate>Fri, 08 Oct 2010 09:56:47 GMT</pubDate></item><item><title>mikeash - 2010-09-29 16:27:46</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Are there actually people in the world who are sufficiently literate enough in English to be able to make an intelligent post to this site, but who are incapable of googling for "humour american spelling"?</description><guid isPermaLink="true">de31b32dd53640f19d412c0edba4193a</guid><pubDate>Wed, 29 Sep 2010 16:27:46 GMT</pubDate></item><item><title>Joan - 2010-09-29 10:08:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>I do not know what percentage of CF are implemented in ObjC or using the Cocoa apis. What I found is that if you decide to toll-brige among them then you should expect penalties only if you do so from Cocoa to CF, not the opposite, but still using only pure CF calls is faster than their Cocoa equivalents. This is what I found:
&lt;br /&gt;
&lt;br /&gt;Fastest: CFArray accessed with CFArrayGetValueAtIndex 
&lt;br /&gt;Faster: CFArray accessed with -objectAtIndex
&lt;br /&gt;Reference: NSArray accessed with -objectAtIndex
&lt;br /&gt;Slower: NSArray accessed with CFArrayGetValueAtIndex
&lt;br /&gt;
&lt;br /&gt;This is consistent among several devices and OS, although actual differences may vary.
&lt;br /&gt;
&lt;br /&gt;Joan Lluch-Zorrilla
&lt;br /&gt;
&lt;br /&gt;btw. Just let me point out that some of your site challege-response questions are not fair for non US people or to whom do not have English as their primary language (specially US English). Consither this one: "Type the word "humour", but with American spelling". Definitely that question can not be solved in a fair way for all humans.
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">f9ea9b8ad2c745e964e4afd9bc11f817</guid><pubDate>Wed, 29 Sep 2010 10:08:21 GMT</pubDate></item><item><title>Uli Kusterer - 2010-04-17 15:14:59</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Folks, this whole discussion is pointless regarding the iPhone: If you look at the Darwin sources, you'll see that the iPhone's CoreFoundation classes are actually implemented in ObjC.
&lt;br /&gt;
&lt;br /&gt;That's right: CFArray and the likes are ObjC classes on the iPhone.</description><guid isPermaLink="true">84b004a6a9b2e8b3a5fdec10f73b2393</guid><pubDate>Sat, 17 Apr 2010 15:14:59 GMT</pubDate></item><item><title>Stuart Carnie - 2010-01-26 07:22:25</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Indeed, the ObjC / CF is pretty much a non-issue on newer hardware.  Certainly not worth the effort.
&lt;br /&gt;
&lt;br /&gt;I was incredibly impressed by the IMP call on the Cortex CPU...wow.
&lt;br /&gt;
&lt;br /&gt;I've implemented the enumerator code before to use the for/in syntax (a simple state machine).  It would be nice if Apple introduced a 'yield' keyword like other languages, to save us having to write the state machine code all the time.  Regardless, it's fairly easy to write and the performance pretty close to the metal.</description><guid isPermaLink="true">798441a2804dc672c33863216cb70626</guid><pubDate>Tue, 26 Jan 2010 07:22:25 GMT</pubDate></item><item><title>mikeash - 2010-01-25 22:03:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Very nice. I like that you were able to benchmark two different types of hardware too.
&lt;br /&gt;
&lt;br /&gt;It looks like the difference between the ObjC and CF calls is &lt;i&gt;approximately&lt;/i&gt; equal to the cost of a message send, which is what I'd expect to see.
&lt;br /&gt;
&lt;br /&gt;Note that in the particular case of iterating over stuff, the fast enumeration for/in syntax is almost certain to be the winner. It uses ObjC messaging to talk to the object, but returns objects in bulk and can return interior pointers, which means that the number of calls/messages will be much smaller than the number of objects in the array.
&lt;br /&gt;
&lt;br /&gt;Of course, there's a lot more stuff out there than just iteration, and no equivalent to fast enumeration for the rest.</description><guid isPermaLink="true">4488182cf9ea85d962a72218530391d2</guid><pubDate>Mon, 25 Jan 2010 22:03:40 GMT</pubDate></item><item><title>Stuart Carnie - 2010-01-25 06:07:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>G'Day again Mike - ended up adding the benchmarks as you suggested.  I posted some information on my blog, and the results are certainly interesting - tested 2nd and 3rd gen iPhones.  My results show the IMP call is faster than the C++ virtual method call, as you originally had expected.
&lt;br /&gt;
&lt;br /&gt;Blog post here: &lt;a href="http://bit.ly/5pxjgk"&gt;http://bit.ly/5pxjgk&lt;/a&gt;
&lt;br /&gt;</description><guid isPermaLink="true">5e12606a3a2a5057946f1212988f254b</guid><pubDate>Mon, 25 Jan 2010 06:07:53 GMT</pubDate></item><item><title>Stuart Carnie - 2010-01-24 18:33:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Great idea, I'll take a look at the test suite and add an additional comparison between equivalent Obj-C / CF.  I'll post the results here when I give it a go.</description><guid isPermaLink="true">bc5aa9ed66f459a2874d2c41be8a390f</guid><pubDate>Sun, 24 Jan 2010 18:33:23 GMT</pubDate></item><item><title>mikeash - 2010-01-24 17:43:17</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>This stuff is definitely still interesting and good to know even if you shouldn't be thinking about it all the time. Perhaps you could add some CF benchmarks to this stuff:
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://mikeash.com/?page=pyblog/performance-comparisons-of-common-operations-iphone-edition.html"&gt;http://mikeash.com/?page=pyblog/performance-comparisons-of-common-operations-iphone-edition.html&lt;/a&gt;</description><guid isPermaLink="true">24d3f2c1ae64f5999b5e8709f0cde837</guid><pubDate>Sun, 24 Jan 2010 17:43:17 GMT</pubDate></item><item><title>Stuart Carnie - 2010-01-24 07:38:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>Absolutely @mikeash - how far our hardware has come.  I'm not one to prematurely optimize code (especially if I don't have numbers to back it up), but I thought it an interesting micro-benchmark exercise.  I'm a firm believer that understanding the mechanics of your "hardware" helps you to make it perform better.  
&lt;br /&gt;
&lt;br /&gt;Cheers and thanks for the informative post,
&lt;br /&gt;
&lt;br /&gt;Stu
&lt;br /&gt;</description><guid isPermaLink="true">2d85027b24dbef7933d1bf255527e232</guid><pubDate>Sun, 24 Jan 2010 07:38:15 GMT</pubDate></item><item><title>mikeash - 2010-01-23 23:37:50</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>The macro looks up the appropriate isa for the given CFType (which I believe is a single array lookup) and then compares it with the object's isa, so the overhead is basically two loads from memory. Not much. Using CF functions is faster than ObjC methods &lt;i&gt;if&lt;/i&gt; the object is a "real" CF object; obviously it's slower if it's actually a pure Objective-C class and the call has to be bounced back to that side. Whether the overhead matters is another question entirely. As with any programming task, favor writing clear code over writing fast code unless speed is proven to matter in the real world. Just because you're on an iPhone doesn't make &lt;code&gt;objc_msgSend&lt;/code&gt; automatically horrible. Remember that NeXTSTEP originally ran on 25MHz 68080s, a CPU roughly 10x slower than the iPhone's ARM, and it did everything with Objective-C.</description><guid isPermaLink="true">1015c30cf24e7191863909a580a53641</guid><pubDate>Sat, 23 Jan 2010 23:37:50 GMT</pubDate></item><item><title>Stuart Carnie - 2010-01-23 22:14:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>What's the overhead of the macro &lt;code&gt; CF_OBJC_FUNCDISPATCH0&lt;/code&gt;?  I would have expected calling the CF C functions a little more efficient, particularly on a resource constrained device like the iPhone.
&lt;br /&gt;
&lt;br /&gt;Perhaps I'll do a few micro-benchmarks and publish the results on my blog (which is in serious need of updating anyhow).  My thought was that when building a reusable iPhone framework using CF/NS classes, one would be better off using the CF* equivalents.
&lt;br /&gt;
&lt;br /&gt;Cheers,
&lt;br /&gt;
&lt;br /&gt;Stu</description><guid isPermaLink="true">fe3facc8db943d179b5c670f0da3be68</guid><pubDate>Sat, 23 Jan 2010 22:14:47 GMT</pubDate></item><item><title>mikeash - 2010-01-23 02:44:47</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>I don't consider either of those to be bridging in the sense used by CoreFoundation. If you write an Objective-C class with a C wrapper, that's just an Objective-C class with a C wrapper. If you implement the class in C, that's just a C library with an Objective-C wrapper which then has a C wrapper too. Not to say that it isn't sometimes useful to do that, it's just not bridging.</description><guid isPermaLink="true">88e7e829c8a72c7850f1bf10dc13635f</guid><pubDate>Sat, 23 Jan 2010 02:44:47 GMT</pubDate></item><item><title>alastair - 2010-01-22 22:13:54</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>You can also optimise what Ken suggests by putting the implementation code into a set of C implementation functions, calling those from the ObjC methods, &lt;i&gt;and&lt;/i&gt; calling them directly from the C API when you know that the object you've been given is of the class you expect.
&lt;br /&gt;
&lt;br /&gt;Obviously this kind of thing is only for use in extreme cases :-)</description><guid isPermaLink="true">10a46edadab8a9c9c49363a99da6a318</guid><pubDate>Fri, 22 Jan 2010 22:13:54 GMT</pubDate></item><item><title>ken - 2010-01-22 21:35:39</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-01-22-toll-free-bridging-internals.html#comments</link><description>On creating bridged classes, you sort of can, you just make the ObjC the primitive and the C side a wrapper for ObjC method dispatch. 
&lt;br /&gt;
&lt;br /&gt;From the outside, it looks the same.  There's a CF-level function interface, there's an ObjC class, the types are interchangeable, and you can subclass the ObjC class and pass it to the the C function interface.
&lt;br /&gt;
&lt;br /&gt;Why would you do this?  Well, there isn't a lot of reason, but sometimes people have files that they want to be pure C.</description><guid isPermaLink="true">b5a9c34d22afe9f6f20c3a0faf081444</guid><pubDate>Fri, 22 Jan 2010 21:35:39 GMT</pubDate></item></channel></rss>
