Why does the computation time for boundingRect of NSAttributedString become significantly longer in iOS15.2?

Why does the computation time for boundingRect of NSAttributedString become significantly longer in iOS15.2?

This is the result measured with the iPhone simulator. (700 lines of Hiragana)

・iPhone13Pro, iOS15.0 : 0.012s

・iPhone13Pro, iOS15.2 : 2.318s

The sample code has been uploaded to github.

Compare iOS 15.2 with iOS 15.1 or lower versions. https://github.com/kimuyonsoku/BoundingRectTest

Is this on a background thread or a main thread.

Could you test on device ?

It is running in MainThread.

https://github.com/kimuyonsoku/BoundingRectTest/blob/main/BoundingRectTest/ViewController.swift

I didn't measure the exact time, but on device, iPhone6s (iOS14.7.1) was very fast and iPhone11Pro (iOS15.2.1) was very slow.

A bug report has been filed [FB9855886]

Thanks.

Looking at your bug it seem likely that this is caused by a string bridging problem. The -boundingRectWithSize:options:attributes:context: method you’re calling is implementing in Objective-C, so it works best when the String value is an NSString under the covers. Something in the OS has caused your string to be converted to a Swift string, which results in a lot of bridging overhead within -boundingRectWithSize:options:attributes:context:.

It’s possible that you could work around this issue by tweaking your code to ensure that your String is actually an NSString. I don’t have a specific recommendation for how to do that. Creating that would take time, more time than I have to spend here on DevForums. You should play around with this concept yourself to see if you can make any headway. If not, I recommend that you to open a DTS tech support incident so that I, or one of my colleagues, can look into this in detail (make sure to reference this DevForums thread).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Why does the computation time for boundingRect of NSAttributedString become significantly longer in iOS15.2?
 
 
Q