Re: Message Forwarding Overhead / Performance
Re: Message Forwarding Overhead / Performance
- Subject: Re: Message Forwarding Overhead / Performance
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 28 Oct 2008 09:09:30 -0700
On Oct 28, 2008, at 8:30 AM, Jerry Krinock wrote:
Although the documentation on message forwarding [1] explains that
alot of stuff needs to happen, it does not say "Warning: Don't do
this in performance-critical applications". So I made a test tool
which forwarded a simple message with one integer argument to a
class which would add it to its 'sum', an instance variable.
Sending this message 10,000 times and comparing the difference in
elapsed time with a similar task that sends a similar message
directly, I found that the average overhead for forwarding one
message on my Intel Core 2 Duo Mac Mini was about 20 microseconds.
That would be unacceptably slow for an iterated operation in a my
application, and I decided to not use message forwarding in this
particular case.
That would not surprise me. An absolute microseconds overhead isn't
a terribly useful measure without knowing the total # of
microseconds. In general, measuring as a factor of speed -- 1.2x 20x
200x is more widely applicable (tends to be more consistent across
different CPUs, for example).
It is highly atypical to employ a design pattern that involves message
forwarding in the midst of a tight loop. While your test case does
test the absolute overhead, it doesn't test what is typically found in
the real world.
How many times does your iterated operation actually iterate? Human
perception generally has a response granularity somewhere around about
120-160 msecs. Your users being above average, let's call it
100msecs. Slight apples and oranges here; "response time" is
literally "time to respond" and we are really considering "perception
of how long something took". Same ballpark and we are going on the
highly optimistic side.
Given 20 microseconds overhead, your loop would have to iterate 5000
times to incur a delay that the user might perceive.
And that, of course, assumes that 20 microseconds of overhead even
matters in your loop. If your actual operation is, say, 50
microseconds then -- sure -- that 33% overhead will add up. At 500
microseconds, you are looking 4% overhead for that one operation and,
quite likely, a fraction of percentage of total CPU time.
So... sure... message forwarding is slow. But does it matter in your
application?
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden