• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: calling method via IMP that returns non id type - compiler warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling method via IMP that returns non id type - compiler warning


  • Subject: Re: calling method via IMP that returns non id type - compiler warning
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Sun, 15 Feb 2004 21:09:51 -0800

Hello...

In doing performance optimization on various random ObjC apps over the years, I have yet to run across a situation where direct IMP access has yielded a useful performance boost outside of the tightest of loops.

Just to provide a concrete example of why doing this specific type of optimization (using IMPs to access methods instead of using normal messaging) is rarely needed, and shouldn't really be considered during the design phase:

At one point I was working on some code for a class that was very similar to NSMatrix and required calculations for the layout of its cells. I had a very simple method for doing layout that returned the rect of a cell at any particular row and column, by calculating the origin for that cell and using a fixed size (basically the equivalent of cellFrameAtRow:column:).

When the matrix was being drawn, the layout method was called once for each "cell" in the matrix. The cell drawing code was using the NSString method drawInRect:withAttributes:, and I wasn't happy with the performance, but that was outside my control at that point. So I figured I would try using an IMP to access the layout method to speed up the loop that caused the cells to be drawn in the matrix drawing method (which iterated through all of the cell positions calculating the location and telling it to draw), since it was being called a significant number of times (and although inlining the layout code would have been faster yet, there were several reasons I didn't want to do that).

So, I wrote a second version of the drawing code for the matrix, with the only difference being that it used an IMP to access the layout method as a function during the loop instead of using obj-C messaging. Let me just say that I was significantly underwhelmed by the performance boost :)

It turned out that my matrix needed to be have more than a 100x100 cell area being drawn to see a significant difference in speed. And when I say significant, I mean a _mathematically_ significant difference, not a noticable difference. I had an NSLog statement at the beginning and end of each verison of the drawing code to record the start and end times. For a matrix that was smaller than about 100x100 cells, the difference is speed between the two versions (impDone - impStart) and (messageDone - messageStart) was generally undetectable... even though NSLog outputs the time down to the millisecond !!! For a 100x100 cell matrix, the layout method would have been called 10,000 times, and the difference in the _total_ time for all 10,000 calls was slightly less than a millisecond (ie more often than not the difference was 0.001 instead of 0.000).

Needless to say, I don't think anyone will notice the difference in speed between using an IMP and using normal messaging even if your method is called frequently, unless it is basically called continuously without anything else happening.

Louis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: calling method via IMP that returns non id type - compiler warning (From: Ben Dougall <email@hidden>)
 >Re: calling method via IMP that returns non id type - compiler warning (From: "b.bum" <email@hidden>)

  • Prev by Date: Better way to deal with NSFontPanel in a preference pane
  • Next by Date: ScalingScrollView with Sketch
  • Previous by thread: Re: calling method via IMP that returns non id type - compiler warning
  • Next by thread: Re: calling method via IMP that returns non id type - compiler warning
  • Index(es):
    • Date
    • Thread