Re: Drawing many different strings quickly
Re: Drawing many different strings quickly
- Subject: Re: Drawing many different strings quickly
- From: Ben <email@hidden>
- Date: Thu, 01 Oct 2015 08:02:08 +0100
> On 28 Sep 2015, at 18:42, Alex Kac <email@hidden> wrote:
>
> We had the same question and I asked it at WWDC. A few things I was told:
>
> 1. El Capitan improves string drawing performance tremendously. That may solve your problem.
> 2. They recommended in our case actually using NSTextFields for each string. They showed me an app that had thousands of NSTextFIelds in a resizable window and it was buttery smooth. Smoother than the same code using NSString drawing functions in the exact same scenario.
>
> Now 100,000 strings may change the equation a bit…but might be worth a quick try.
> <snip>
> Alex Kac - El capitán
Just for a final follow-up now El Capitan is public.
0. I really am not trying to draw the whole view at once. It's just that you can scroll the whole grid vertically or horizontally in a single flick on a trackpad in about a second.
1. I should have mentioned that I am writing in Swift. I've become so accustomed to it that it's easy to forget it still has some slower bits.
Using NSString's drawInRect:withAttributes: wants a Swift dictionary of attributes. Instruments showed a lot of time spend accessing the elements of this dictionary and converting back to Objective-C land.
Converting the string to be drawn to an NSAttributedString and adding attributes to it directly before drawing with drawInRect: resulted in string drawing dropping from ~65% of drawRect time to ~50%.
2. Upgraded to 10.11 overnight last night and ran the same profile again. drawRect now spends around 35% of time drawing strings. The calls underneath drawInRect look vastly different. Thank you to whoever put this work in at Apple.
Drawing speed of the control is now fine and scrolling is smooth. I will have a small play with drawing options in case there more headroom that can be quickly gained, but am currently very happy.
Thank you all for the assistance.
- Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden