Deleting QChart Causes 30+ Second Application Hang!
-
@FleetingMemory
As you have now discovered, it is the deleting of each series which is so time consuming (for unknown reasons). There is a huge difference between 10 series with 10,000 points each versus 10,000 series with 10 points each. (In fact, in latter case timing is same even if all series are empty/have no points.) There seems to be little you can do to affect that timing. I see no evidence it has anything to do with whether the view/chart/series are shown or not, have signals disabled or not, etc.Which takes me back to my question as to why you need 10,000 series or any such figure, which you did not answer. There is no chance the user can view or appreciate such a large number, so what is the point of adding that many onto the chart in the first place? That is where I would look for efficiency improvement.
If you really are not prepared to reduce that, then: I presume any
deleteLater()
won't help as that just delays when the delay comes to a bit later. I assume you are right that series cannot or should not be deleted from a thread as they are some kind of UI object. Which would leave you with one possible "hack" to distribute the deletion time "nicely". Follow @JoeCFD's code to assign a new, blank chart to the view (chartView->setChart( new QChart() );
). But do not immediately delete the original chart there: instead, keep it around in a suitable variable. In UI code thread set off a repeating timer every so often: in each timeout useremoveSeries()
to delete a few of the 10,000 series, example perhaps 100 at a time. You can do this because you are in the main/UI thread. Over time you will have deleted all the series from the oldQChart
object, at that point you can delete the (empty) chart and terminate the timer. Seems to me reducing the number of series in the first place is preferable, but there you are if you really want to do this. -
@JonB said in Deleting QChart Causes 30+ Second Application Hang!:
Which takes me back to my question as to why you need 10,000 series or any such figure, which you did not answer. There is no chance the user can view or appreciate such a large number, so what is the point of adding that many onto the chart in the first place? That is where I would look for efficiency improvement.
The chart is to be used for displaying & isolating specific data/time frames, thus all data/lines need to be present, and each series is a line being displayed. By manipulating the X-Axis the user can zoom into/out of to a specific time frame. The idea of deleting a few at a time is something I have definitely been exploring as a possible solution however it doesn't fix the fact it will still hang the whole application when the window is closed or application exited as well.
-
@FleetingMemory that is why I wrote earlier that you need a splash widget with some nice animation at exit and make your app wait for these series to be cleared.
You can also file a bug with Jon's test code to Qt for optimization in removeAllSeries call. I guess one update may be enough instead of one update after one deletion.
-
I've tested @JonB 's code with 12000 series / 40 data points each in debug mode:
Starting to create
Finished creating 32858
Starting to delete
Finished deleting 195421Digged a little bit around to see what happens during destruction. The most time the legend gets updated... so:
I added this beforedelete chart;
:
delete chart->legend();
-->
Starting to create
Finished creating 33861
Starting to delete
Finished deleting 27167The best thing I found is to add
d_ptr->m_dataset->disconnect();
in QChart dtor. I doubt this will go in into official QtCharts since it's in maintainance mode only.-->
Starting to create
Finished creating 31901
Starting to delete
Finished deleting 16988 -
@Christian-Ehrlicher
All I saw was all the time being spent inremoveAllSeries()
, or whichever you remove series if one by one. I looked atremoceSeries()
source code online but I don't have sources to dig further. I don't know how that is affected by legend. Nothing struck me except however it is storing its model data. That could relate to yourd_ptr->m_dataset
. Andd_ptr
requires OP to change and compile Qt sources, right?It's taking 30 seconds to get rid of 10,000 series which it never took 30 seconds to create, it is a lot of time per series.
P.S.
Of course, as you say QtCharts is going so realise nothing is going to be done about sources. -
@Christian-Ehrlicher I currently have legend disabled, is it still updating in the background even with it off?
-
original bug report was ignored, had to refile and explain more. Linked the new report below
-
@JoeCFD Filed the bug report yesterday -- Feel free to add any findings to it!
https://bugreports.qt.io/browse/QTBUG-134490 -
As I already said QtCharts is deprecated. Nothing will be changed there. I gave you two solutions...
-
@FleetingMemory They will not fix it for you. Maybe you can dig into the source code of this module and try some fixes. Then build it for yourself.