swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Re: integers


From: Marcus G. Daniels
Subject: Re: [Swarm-Support] Re: integers
Date: Wed, 07 Feb 2007 12:23:20 -0700
User-agent: Thunderbird 2.0b1 (Windows/20061206)

Paul Johnson wrote:
I often wondered if there is speedup involved if you make an instance variable public and then get the value out with the -> operator rather than doing the Objective-C thing [x getValue].
Messaging an object involves a lookup of the method implementation (e.g some subclass's implementation of getValue as opposed to a base class's implementation), and then calling it and then returning to the right place in the caller. Logically, this is a lot more work than looking in a particular spot in memory. In practice, it can be much worse because the processor will be making control flow changes just to get you your value. A modern microprocessor is trying to make many decisions in advance, and _speculatively_ on your behalf. Objective C dynamic typing means that these decisions are more complicated to anticipate because each one depends on what is *in* an object and that can change (e.g. with Swarm lifecycle phases). So, unfortunately a seemingly innocuous message like this can stall what should be a deep pipeline of work that that microprocessor is designed to accumulate, and then execute in parallel on its multiple internal execution units. One technology to deal with this problem is called Dynamo http://www.cag.lcs.mit.edu/dynamorio/ Rather than executing code directly, a initially virtual CPU executes your code. It watches what your code does and notices (better than a real CPU can), what branches are actually taken under what circumstances. Then, after a period of observation, it can generate native code inline and do the right thing at full speed. Slow start up, but fast in the long run. I experimented with this package and some Swarm models and saw some speedups. Its a research project, though, and by no means a magic solution. There's no substitute for designing and refining code to be fast. (And remembering that not everything needs to be.)

If you're not sure that a value will always be a scalar and appropriate to grab with "->", instead of a requested or computed value, you can uses macros that are implemented using "->" initially and reserve the right to change it to a [obj getValue] or getValue (). e.g.

#define GETVALUE(obj) ((MyObject *)obj)->value)

and as needed:

#define GETVALUE(obj) [obj getValue]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]