Optimizing NSNumber numberWithInt:

Posted by Riviera on Stack Overflow See other posts from Stack Overflow or by Riviera
Published on 2012-03-27T01:08:46Z Indexed on 2012/03/27 5:29 UTC
Read the original article Hit count: 164

I am profiling an iPhone app and I noticed a strange pattern. In a certain block of code that's called quite frequently...

    [item setQuadrant:[NSNumber numberWithInt:a]];
    [item setIndex:[NSNumber numberWithInt:b]];
    [item setTimestamp:[NSNumber numberWithInt:c]];
    [item setState:[NSNumber numberWithInt:d]];
    [item setCompletionPercentage:[NSNumber numberWithInt:e]];
    [item setId_:[NSNumber numberWithInt:f]];

...the first call to [NSNumber numberWithInt:] takes an inordinate amount of time, in the order of 10-15x that of the remaining calls. I've verified that the results are consistent if I shuffle the lines (the first line is always the slow one, by the same ratio). Is there something going on that I'm not aware of?

Perhaps this happens because this block is inside a try/catch?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c