If your code is performance sensitive enough that you have to consider cache locality of static strings, you may consider replacing your logging code by dtrace USDT (User-Level Statically Defined Tracing).
To do that, you just create a primes.d file that contains the list of probe you want to define:
provider primes {
/* Start of the prime calculation */
probe primecalc__start(long prime);
/* End of the prime calculation */
probe primecalc__done(long prime, int isprime);
/* Exposes the size of the table of existing primes */
probe primecalc__tablesize(long tablesize);
};
You add that file to your Xcode project, and it will automatically generate the corresponding header.
You can the include the header in your source:
--------
#include "primes.h"
long prime(long value) {
PRIMES_PRIMECALC_START(value);
….
PRIMES_PRIMECALC_DONE(result);
if (PRIMES_PRIMECALC_TABLESIZE_ENABLED()) {
// Do some computation useless when probe disabled.
PRIMES_PRIMECALC_TABLESIZE(size);
}
}
--------
Note that even if some code is conditionally protected by a if branch, the linker replace it at link time by custom dtrace code, so you don’t have to pay for it (dtrace is designed to cost nothing when disabled).