Core Plot IPad performance issue - ios

In my app, i got core plot bar chart on a scroll view with paging, on IPhone all work fine , you page between different pages, one of them is the plot with its own touch gestures and properties.
Problem starts when i run the same code on IPad. plot becomes slow and laggy, all touch gestures takes a lot of time to response and the whole scroller paging becomes heavy and slow.
the chart itself contains 100 points or so (not so big).
I've read somewhere that the change of plot space between IPhone and IPad makes these changes in performance because the IPad renders 4 times the graphics. Did anybody had this problem before? Is there something i can do to make performance better on IPad without limit or lose preform data?

Unfortunately Core plot is a very slow library which can only handle a few hundred data-points (or less in some cases).
I wrote an answer here which describes a performance comparison between iOS chart components. One of the charts tested was core-plot and it couldn't do the first test!

Without knowing the specifics of your app, here are some general performance hints:
Set all line styles and fills that you don't need to nil rather than transparent colors.
Use solid color fills rather than gradients or images where possible.
Reduce the number of axis labels, tick marks, and grid lines if possible. Perhaps eliminate minor tick marks and grid lines completely (set the corresponding line styles to nil).
Only call -reloadData when a significant portion of the plot data changes. Use the insert and delete methods when possible. See the "Real Time Plot" in the Plot Gallery example app.

Related

Which is a better option for displaying irregular shapes in Swift?

let me start off by showing that I have this UIImageView set up in my ViewController:
Each one of the lines contains a UIButton for a body part. If I select a particular button, it will segue me appropriately.
What'd I like to do is, when the user taps (but doesn't release) the button, I'd like the appropriate body part to show like this:
I can achieve this using 2 options:
UIBuzierPath class to draw, but would take a lot of trial and error and many overlapping shapes per body part to get fitting nicely as similiar in a previous question: Create clickable body diagram with Swift (iOS)
Crop out the highlighted body parts from the original image and position it over the UIImageView depending on which UIButton selected. However there would only be one image per body part, but still less cumbersome then option 1.
Now, my question is not HOW to do it, but which would be a BETTER option for achieving this in terms of cpu processing and memory allocation?
In other words, I'm just concerned about my app lagging as well as taking up app size storage. I'm not concerned about how much time it takes to do it, I want to just make sure my app doesn't stutter when it tries to draw all the shapes.
Thanks.
It is very very very unlikely that either of those approaches would have any significant impact on CPU or memory. Particularly if in option 2, you just use the alpha channels of the cutout images and make them semitransparent tinted overlays. CPU/GPU-wise, neither of the approaches would drop you below the max screen refresh rate of 60fps (which is how users would notice a performance problem). Memory-wise, loading a dozen bezier paths or single-channel images into RAM should be a drop in the bucket compared to what you have available, particularly on any iOS device released in the last 5 years unless it's the Apple Watch.
Keep in mind that "premature optimization is the root of all evil". Unless you have seen performance issues or have good reason to believe they would exist, your time is probably better spent on other concerns like making the code more readable, concise, reusable, etc. See this brief section in Wikipedia on "When to Optimize": https://en.wikipedia.org/wiki/Program_optimization#When_to_optimize
Xcode have tests functionality built in(and performance tests too), so the best way is to try both methods for one body part and compare the results.
You may find the second method to be a bit slower, but not enough to be noticed by the user and at the same time a lot more easier to implement.
For quick start on tests here.
Performance tests here.

UICollectionView scroll lags with core plot

I'm using a UICollectionView on my iPad 3 to display a dashboard of BarChart using CorePlot. I have around 3 pages of 6 BarChart.
When user scrolls the UICollectionView there're some lags.
I have changed the theme of my BarChart from kCPTDarkGradientTheme to kCPTPlainBlackTheme and the scroll is much better but it still lags a little.
From instrument it seems it takes some times (160ms) in -(void)recursivelyRenderInContext:(CGContextRef)context from CPTLayer.
Any idea how to improve it?
Regards,
Sébastien.
Solid colors render a lot faster than gradients, so that explains the improvement when you changed themes. Are you caching the generated graph images so they only have to render once? The iOS version of the Plot Gallery example app use a table view to show the graph thumbnails, but it might give you some ideas how to structure your app for better performance.

Highcharts Performance Enhancement Method?

My highchart diagram is loading extremely slow due to large amount of data (one data per day for the past 10 years). I already turned off the animation. And it is still slow. Is there a way to speed up or performance improvement to allow faster loading time and able to zoomed in without any lags? Thanks.
The webpage with the highchart is only 77kb though.
You can use dataGrouping and set enableMouseTracking to false.
enableMouseTracking: Boolean
Enable or disable the mouse tracking for a specific series. This includes point tooltips and click events on graphs and points. When using shared tooltips (default in stock charts), mouse tracking is not required. For large datasets it improves performance. Defaults to true.
Update
Found the following on it's docs.
How can I get the best performance out of Highcharts?
When working with series with a high number of data points, there are a few things to consider.
For line plots, it is recommended that you disable point markers, as these will add a performace overhead. See http://highcharts.com/demo/line-time-series.
Disabling shadows increases performance, as three shadow elements are created for each shape that includes a shadow.
For large column series, it is recommended that you disable the initial animation, plotOptions.column.animation, at least for VML based browsers. The best way to distinguish between fast SVG browsers and slower VML browsers is to use the Highcharts.svg boolean property.
Reference
enableMouseTracking
dataGrouping
FAQ

Core Plot - Drawing only the points in a specific range of the graph

I have a simple scatter plot with ~500,000 points on it. Having this many points on the graph really makes my app lag, which isn't surprising. I was wondering if there was a way to only draw the points for a specific x range (like 0-100 or 500-1000). The user will only be looking at certain points of the graph (via zooming in), so it would make it much less laggy if the program only had to plot a small amount of those points.
I've tried having the graph re-draw itself, every time the user zooms in/out or moves the axis, but this actually seems to make the app run slower. Is there a solution to this issue?
You'll have to filter the data and only provide the visible points to the plot in your datasource. Use a plot space delegate to detect when the visible area changes and adjust the data as needed. The best way to do this will depend on how your app stores its data internally. You'll want to use a data structure that lets you quickly determine which points need to be plotted.
You don't want to reload all of the data every time something changes. The plots have methods to insert and remove ranges of data points while preserving the rest of the data. If you're only changing a few points at a time, this is much faster than reloading all of the data every time. The "Real-Time Plot" demo in the Plot Gallery app shows one way to use these methods.

Do I still need to pad images in a CSS Sprite?

In CSS Sprites you will often find padding between each image. I believe the idea is so that if the page is resized then one image won't bleed into another.
I think this depends on the different types of browser zoom (best explained by Jeff).
However, I haven't been able to see this behaviour in my tests. Is this only a problem with older browsers? (I havent been able to test with IE6 at the current time so I'm counting that as 'old').
Should I still worry about leaving space? Its kind of a pain.
For instance :
A CSS Sprite I found for AOL has
padding between each image : VIEW
but The Daily Show decided not to
bother : VIEW
It shouldn't need to be padded, but when zoomed, especially in IE8 (betas more than the RC), there is image bleeding if there is no padding.
Best example is to go to Google.com -> Search, and zoom... you'll start to see "underlines" at the bottom right of the image as the zooming rounds up/down.
In theory, a 1px padding on all sides of a sprite should be fine.
Here's the sprite from Google (images)...
But when zoomed, the +,-,x icons bleed into the main Google logo.
Basically the answer is yes. Two years to the day after I asked this question will see the release of IE9. IE9 has this problem just as much - if not more than any other browser...
It's pretty infuriating because it's such a simple thing to fix.
With iPads increasing in marketshare - its's pretty essential to at least have a half decent experience with zooming un-uniform amounts.
I am going to have to put a single pixel border around every image to match the background color of the adjacent element (potentially different on each side). Fortunately I auto-generate all my csssprites based on an .xml file - so I can do this programatically without too much hastle. It's still a huge pain though...
Simon - My experience is that this is certainly still a problem.
In response to your second question, why not use transparent padding? (Perhaps you are still supporting ie6 and this is non-trivial, in which case, I'm really sorry).
Speaking of the older browsers (those using text zoom), you don't always need padding.
The main difference between your two examples is that the Daily Show sprite already includes the menu item's text in the image itself.
When using text zoom, the AOL menu items could stretch out vertically due to the larger font size, and the menu text might even wrap to two lines. To accommodate for such eventualities, those icons need a little padding to ensure they don't bleed. Typically, you'd just try to make sure it doesn't bleed on any of IE6's five text sizes.
Since The Daily Show's menu doesn't contain any (visible) HTML text its size won't be affected by text zoom (though you might need a line-height: 0; or so to be sure), so it doesn't need any padding.
As scunliffe already showed, browsers using page zoom may need sprites to have a little padding due to rounding errors.

Resources