Is it normal for string operations to be very expensive on the iPhone?

I kind of already know the answer to this from other platforms, but i've just recently been trying to optimise my project which had started to get very slow on my original iPhone. Developing on a 3GS can definitely hide things from you.

Anyways, a good chunk of this performance hit has something to do with my physics setup, i think i've got it about as optimised as possible now.

However i was left with a general amount of profiled mono scripts update.. 4-6% (of a frame i presume). Even when it was doing what I really expected to be nothing.

In the end i selectively removed functionality and went through the tedious rebuilding on the much slower older phone.

Finally figuring out that some of my debug functions were actually very expensive, even though their function bodies were disabled on a #define.

Basically what transpires is that just doing string ops like

Debug.Log("pos = " + transform.position);

can add a real significant percentage on the update, along with a corresponding decrease in framerate, and crucially a big increase in mono memory usage fluctuation. Large amounts of which seems to perhaps lead to more garbage collection and frame spikes.

Anyways, I just wanted to know if anyone had spotted this and had any tips for improvements. I've already disabled a lot of my debugging logs and other outputs. But i think i need to really look into a better way of removing them all on-mass, in absence of global #defines or C#'s ability to completely remove members on a #define. I'd hope the latter would remove any calculations on the calling side as well.

Anyways, it seems strings == very bad!

A few things, accessing the transform using `.transform` does something like: `(Transform)GetComponentOfType(typeof(Transform))` Better is to cache this value, do something like:

private Transform myTransform;

void Awake() {
    myTransform = transform;
}

...
    Debug.Log("pos = " + myTransform.position);
...

(and of course us myTransform instead of transform everywhere in the class)

Also, the `Vector3` is converted to a `string`, and then the result is added to the string. Then the Debug output is written to `stdout`, even if you're not capturing it, it does still consume time to write to the log.

Considder having a `public static const bool DEBUG = false` defined in some class (like `Globals.cs` or something) and use:

if (Globals.DEBUG) {
    Debug.Log(...)
}

Whenever doing things that are for debug purposes only, yes the compiler will compile const expressions away if they're false.