iOS CoreText Slowing Down Plot Render on First Draw?
This discussion was imported from CodePlex
benhysell wrote at 2014-03-10 18:24:
Just pulled down the latest where CoreText is now being used for the text...everything looks great, but it feels like we lost a good deal of speed while rendering the plots. I have a noticeable lag from launching the application to first render.
Hooking up Instruments, I can dig down and see all of the time is being spent in CoreText inside OxyPlot.
This is noticeable on the simulator, and becomes in your face on the device.
In the example OxyPlot program check out the 'LineSeries' examples. Pick a plot, any plot, and you'll have a bit of a pause, and then the graph draws. After this, pick any other LineSeries and you won't have the lag, and it draws fine. Same thing happens on device and in the simulator. Using Instruments to profile I see the same results, a lot of time spent down in CoreText.
If you kill the application, start it up again, and pick a different plot you'll see the same results, long pause, draw plot, and then any other plot after that will draw fine.
Thoughts?
Hooking up Instruments, I can dig down and see all of the time is being spent in CoreText inside OxyPlot.
This is noticeable on the simulator, and becomes in your face on the device.
In the example OxyPlot program check out the 'LineSeries' examples. Pick a plot, any plot, and you'll have a bit of a pause, and then the graph draws. After this, pick any other LineSeries and you won't have the lag, and it draws fine. Same thing happens on device and in the simulator. Using Instruments to profile I see the same results, a lot of time spent down in CoreText.
If you kill the application, start it up again, and pick a different plot you'll see the same results, long pause, draw plot, and then any other plot after that will draw fine.
Thoughts?
objo wrote at 2014-03-10 21:24:
Thanks for the report! I did not notice this on my device, but I have only been testing simple examples.
I think we need to avoid disposing CTLine, NSAttributedString and CTFont objects all the time. And maybe the fonts can be cached? I think the UIFont.Fromname call should also be removed.
ps. is the text aligned correctly horizontally? to me it looked a little bit off.
I think we need to avoid disposing CTLine, NSAttributedString and CTFont objects all the time. And maybe the fonts can be cached? I think the UIFont.Fromname call should also be removed.
ps. is the text aligned correctly horizontally? to me it looked a little bit off.
benhysell wrote at 2014-03-10 23:33:
The title text did seem off center by a bit...yes.
benhysell wrote at 2014-03-20 02:09:
I went back to Instruments with my app, it appears most of the time is spent in
Does anyone have a preferred method for caching the possible different font sizes/font families?
public override OxySize MeasureText (string text, string fontFamily, double fontSize, double fontWeight)
specificallyvar attributedString = new NSAttributedString (text, new CTStringAttributes {
ForegroundColorFromContext = true,
Font = new CTFont (fontFamily, (float)fontSize)
});
The time killer is the new CTFont (fontFamily, (float)fontSize)
Does anyone have a preferred method for caching the possible different font sizes/font families?
benhysell wrote at 2014-03-20 14:53:
I played around with caching
tldr
The more attributes a string has the longer it takes to draw.
I've since changed the code to:
CTFont
and did not get the performance benefit I thought I might. After a little more digging I turned up
http://stackoverflow.com/questions/6062420/core-text-performance. tldr
The more attributes a string has the longer it takes to draw.
I've since changed the code to:
var attributedString = new NSAttributedString (text, new CTStringAttributes {
// ForegroundColorFromContext = true,
// Font = new CTFont (fontFamily, (float)fontSize)
});
Commenting out the color and font greatly improves performance, I'd say it is as fast as it was before moving to CoreText.benhysell wrote at 2014-04-05 16:35:
Latest release has put this issue to bed...plots no longer lag on first draw!
Nice work!
Nice work!
benhysell wrote at 2014-04-05 16:37:
It is safe to close issue
https://oxyplot.codeplex.com/workitem/10162
Customer support service by UserEcho