Hi,
I'm seeing high CPU usage on a chart when loading certain data. It's not 100% reproducible, but close to 100% if I have the right data set.
Here's a stack trace from Instruments:
Running Time Self Symbol Name98136.0ms 98.4% 0.0 Main Thread 0x17bb2a98136.0ms 98.4% 824.0 main54097.0ms 54.2% 0.0 -[TimerCallback dispatch:]54097.0ms 54.2% 4.0 __35-[GChartContentManager makePending]_block_invoke43165.0ms 43.2% 1.0 -[CanvasElement drawRect:]43164.0ms 43.2% 0.0 -[CanvasRenderer drawRect:]43164.0ms 43.2% 28.0 -[CanvasRenderer draw:]43136.0ms 43.2% 754.0 -[CanvasRenderer drawImage:]42382.0ms 42.5% 0.0 __31-[GCanvasViewRenderer setData:]_block_invoke42381.0ms 42.5% 3.0 -[GCanvasViewRenderer renderCallbackWithCtx:data:]42378.0ms 42.5% 9.0 -[GCanvasRenderScheduler renderTargets]40664.0ms 40.7% 20.0 -[GSeriesView renderWithClearRect:]35959.0ms 36.0% 1.0 -[GLineSeriesView renderOverrideWithContext:isHitContext:]35956.0ms 36.0% 5.0 -[GCanvasViewRenderer renderPathWithPath:]35946.0ms 36.0% 28870.0 -[GCanvasViewRenderer renderPathWithPath:gradientDirection:gradientBounds:]
Again, this only happens to charts with lots of data, it seems... maybe it's happening to graphs that don't render fully on one run of the runloop.
Thoughts?
Caylan
I was able to work around this possible race condition by initially setting all series' dataSource to nil. Then, I performSelector:withDelay and set the dataSources to self.
It's also worth noting that while at 100%, if I can get the chart to insert an item (via our app), then the CPU immediately falls back down to normal levels. What I'm saying is, running chart's insertItem:atIndex: unsticks whatever is causing 100% CPU usage (above).
Hi Caylan,
So this was happening on initial load of data? I will try reproducing it.Any idea what sort of data could be causing this?
Yes, initial load. If I had to guess... I think it has to do with some kind of built-in timer that was added that allows the chart to render in sections. The problem is some kind of race condition between checking to see if it's fully rendered and actually loading the view, and then it re-renders over and over. I'd check all the conditions of "fully rendered" and see if that code is being bypassed somehow. Because, one more full renderings nullifies the CPU usage.