Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GUI events slow down long computations
Forum Updated to NodeBB v4.3 + New Features

GUI events slow down long computations

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 4 Posters 4.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J J.Hilk
    5 Jul 2018, 14:43

    I‘m Preto sure, that your Series Append function allows an append<QList<QPointF> > if you cange your Vector to a Qlist, you Could prevent the whole for loop 

    E Offline
    E Offline
    engsml
    wrote on 5 Jul 2018, 15:04 last edited by
    #10

    @J.Hilk My file is too big ): the GUI is not responding when I try this.

    J 1 Reply Last reply 5 Jul 2018, 16:05
    0
    • E engsml
      5 Jul 2018, 15:04

      @J.Hilk My file is too big ): the GUI is not responding when I try this.

      J Offline
      J Offline
      JonB
      wrote on 5 Jul 2018, 16:05 last edited by JonB 7 May 2018, 16:10
      #11

      @engsml
      Hang on a minute. Let's look at your code, please:

      int arrSize = 4096; //for incrementing in intervals
      for(int i = 0; i < arr.size(); i += arrSize) //Plots in increments of 4096
          plot(arr, (i + 4096));
      

      This passes first 0+4096, then 4096+4096, then 8192+4096, then....

      void myClass::plot(QVector<QPointF> arr, int size)
          for(int i = begin; i < size; i++){
      

      arr is always the original array. I presume (I'm not C++) begin is always 0. size is bigger (by 4096) every time plot is called.

      Aren't you (re-)plotting more & more points --- specifically, all points from 0 up to where you have progressed to --- every time you call plot() in your batches?? Or am I going loopy?

      E S 2 Replies Last reply 5 Jul 2018, 16:14
      0
      • J JonB
        5 Jul 2018, 16:05

        @engsml
        Hang on a minute. Let's look at your code, please:

        int arrSize = 4096; //for incrementing in intervals
        for(int i = 0; i < arr.size(); i += arrSize) //Plots in increments of 4096
            plot(arr, (i + 4096));
        

        This passes first 0+4096, then 4096+4096, then 8192+4096, then....

        void myClass::plot(QVector<QPointF> arr, int size)
            for(int i = begin; i < size; i++){
        

        arr is always the original array. I presume (I'm not C++) begin is always 0. size is bigger (by 4096) every time plot is called.

        Aren't you (re-)plotting more & more points --- specifically, all points from 0 up to where you have progressed to --- every time you call plot() in your batches?? Or am I going loopy?

        E Offline
        E Offline
        engsml
        wrote on 5 Jul 2018, 16:14 last edited by engsml 7 May 2018, 16:15
        #12

        @JonB the 'begin' variable also increases by 4096 each time. so the pattern goes:
        begin: 0... size: 4096
        begin: 4096.. size: 8192
        begin: 8192... size: 12288 etc..
        it increases at the bottom of the plot function, begin += 4096 :)

        edit: the plot is correct and what is expected from my txt file, just reeeeaallly slow when buttons are pressed (presumably from the processEvents(); function in the loop)

        J 2 Replies Last reply 5 Jul 2018, 16:20
        0
        • E engsml
          5 Jul 2018, 16:14

          @JonB the 'begin' variable also increases by 4096 each time. so the pattern goes:
          begin: 0... size: 4096
          begin: 4096.. size: 8192
          begin: 8192... size: 12288 etc..
          it increases at the bottom of the plot function, begin += 4096 :)

          edit: the plot is correct and what is expected from my txt file, just reeeeaallly slow when buttons are pressed (presumably from the processEvents(); function in the loop)

          J Offline
          J Offline
          JonB
          wrote on 5 Jul 2018, 16:20 last edited by
          #13

          @engsml said in GUI events slow down long computations:

          the 'begin' variable also increases by 4096 each time.

          Oh, you mean that's your variable you don't show but increment yourself. I was thinking it was some kind of std::list::begin iterator on the list of points.

          Your plot would not have gone wrong, just it would contain loads of "duplicate" points. But I take the point about the buttons being the issue.

          1 Reply Last reply
          0
          • E engsml
            5 Jul 2018, 16:14

            @JonB the 'begin' variable also increases by 4096 each time. so the pattern goes:
            begin: 0... size: 4096
            begin: 4096.. size: 8192
            begin: 8192... size: 12288 etc..
            it increases at the bottom of the plot function, begin += 4096 :)

            edit: the plot is correct and what is expected from my txt file, just reeeeaallly slow when buttons are pressed (presumably from the processEvents(); function in the loop)

            J Offline
            J Offline
            JonB
            wrote on 5 Jul 2018, 16:25 last edited by
            #14

            @engsml said in GUI events slow down long computations:

            just reeeeaallly slow when buttons are pressed (presumably from the processEvents(); function in the loop)

            I do think you ought explain what a button actually does? The whole point is that the processEvents() allows whatever code for on clicked to actually run, so of course if it does much stuff it's going to slow things down. If a button's click does basically nothing, then the overhead is much smaller. If you just click a button (rather than keep clicking it) which does nothing, it shouldn't take any more time than if you don't click a button (but still have processEvents() in the code), if you're saying it does?

            E 1 Reply Last reply 5 Jul 2018, 16:38
            0
            • J JonB
              5 Jul 2018, 16:25

              @engsml said in GUI events slow down long computations:

              just reeeeaallly slow when buttons are pressed (presumably from the processEvents(); function in the loop)

              I do think you ought explain what a button actually does? The whole point is that the processEvents() allows whatever code for on clicked to actually run, so of course if it does much stuff it's going to slow things down. If a button's click does basically nothing, then the overhead is much smaller. If you just click a button (rather than keep clicking it) which does nothing, it shouldn't take any more time than if you don't click a button (but still have processEvents() in the code), if you're saying it does?

              E Offline
              E Offline
              engsml
              wrote on 5 Jul 2018, 16:38 last edited by
              #15

              @JonB The buttons mainly do stuff like scroll left or right, set the range to autoscale the plot, zoom in/out and save a screenshot. All the methods are found in the QChart API and only have about 1 line of code each.

              I can imagine the overlaps plot twice (i.e when begin is 4096 but also the end of the last loop when size was 4096) but I am not too sure if there are other duplicates. Am I missing something?

              J 1 Reply Last reply 5 Jul 2018, 17:33
              0
              • E engsml
                5 Jul 2018, 16:38

                @JonB The buttons mainly do stuff like scroll left or right, set the range to autoscale the plot, zoom in/out and save a screenshot. All the methods are found in the QChart API and only have about 1 line of code each.

                I can imagine the overlaps plot twice (i.e when begin is 4096 but also the end of the last loop when size was 4096) but I am not too sure if there are other duplicates. Am I missing something?

                J Offline
                J Offline
                JonB
                wrote on 5 Jul 2018, 17:33 last edited by JonB 7 May 2018, 17:35
                #16

                @engsml
                Don't worry about what I said about duplicates. I'll assume your code is correct there. I just misunderstood what your begin was.

                I'm still not sure just what your expectation/experience is. If you press a button to change how the chart looks (like scrolling or zooming or whatever), every time you click it will do so. That will interrupt your adding of new points till the action is finished, so naturally the final, overall plot time will end up being longer. Would you not expect that?

                But if you do not click a button, but do have the processEvents() in there, the only extra thing that is happening is that the chart is getting redrawn (points added) as it goes along. Which will also be slower overall than not redrawing till the whole thing is finished.

                I still say you are calling processEvents() too frequently. You should use a batch size. If you say 4096 makes it too unresponsive, at least try 10% of that (400, 100, whatever) rather than calling it for every single point appended.

                E 1 Reply Last reply 5 Jul 2018, 17:55
                2
                • J JonB
                  5 Jul 2018, 17:33

                  @engsml
                  Don't worry about what I said about duplicates. I'll assume your code is correct there. I just misunderstood what your begin was.

                  I'm still not sure just what your expectation/experience is. If you press a button to change how the chart looks (like scrolling or zooming or whatever), every time you click it will do so. That will interrupt your adding of new points till the action is finished, so naturally the final, overall plot time will end up being longer. Would you not expect that?

                  But if you do not click a button, but do have the processEvents() in there, the only extra thing that is happening is that the chart is getting redrawn (points added) as it goes along. Which will also be slower overall than not redrawing till the whole thing is finished.

                  I still say you are calling processEvents() too frequently. You should use a batch size. If you say 4096 makes it too unresponsive, at least try 10% of that (400, 100, whatever) rather than calling it for every single point appended.

                  E Offline
                  E Offline
                  engsml
                  wrote on 5 Jul 2018, 17:55 last edited by
                  #17

                  @JonB Thanks for your help! I included this code snippet in my for loop (I created a variable to help track each 10th element). It seems to run much faster. I'll test it out a bit more and see what the 'magic number' is. Thanks so much again for all your help.

                  if(currentIndex % 10 == 0)
                  {
                      QCoreApplication::processEvents();
                  }
                  J 1 Reply Last reply 5 Jul 2018, 18:02
                  0
                  • E engsml
                    5 Jul 2018, 17:55

                    @JonB Thanks for your help! I included this code snippet in my for loop (I created a variable to help track each 10th element). It seems to run much faster. I'll test it out a bit more and see what the 'magic number' is. Thanks so much again for all your help.

                    if(currentIndex % 10 == 0)
                    {
                        QCoreApplication::processEvents();
                    }
                    J Offline
                    J Offline
                    JonB
                    wrote on 5 Jul 2018, 18:02 last edited by
                    #18

                    @engsml
                    Yep, that's 1 in 10. Like I suggested, I'd be looking for more like 1 in 100 or 1 in 400 as being frequent enough. (I'm surprised that 4096 is too "lumpy" in the first place.)

                    E 1 Reply Last reply 5 Jul 2018, 18:58
                    1
                    • J JonB
                      5 Jul 2018, 18:02

                      @engsml
                      Yep, that's 1 in 10. Like I suggested, I'd be looking for more like 1 in 100 or 1 in 400 as being frequent enough. (I'm surprised that 4096 is too "lumpy" in the first place.)

                      E Offline
                      E Offline
                      engsml
                      wrote on 5 Jul 2018, 18:58 last edited by
                      #19

                      @JonB Yeah it seems 100 is a good number where it still remains fast and responsive. I'm pretty surprised too! My file is about 300,000 coordinates which is probably a lot less data than most large scale programs. I would've assumed Qt and C++ are quicker at processing it.

                      J 1 Reply Last reply 5 Jul 2018, 19:14
                      0
                      • E engsml
                        5 Jul 2018, 18:58

                        @JonB Yeah it seems 100 is a good number where it still remains fast and responsive. I'm pretty surprised too! My file is about 300,000 coordinates which is probably a lot less data than most large scale programs. I would've assumed Qt and C++ are quicker at processing it.

                        J Offline
                        J Offline
                        JonB
                        wrote on 5 Jul 2018, 19:14 last edited by
                        #20

                        @engsml
                        300k points-odd is still a lot of points, though having no experience I don't know what to expect. I don't suppose your average end-user will notice each one of those. If you only add 1 in 10 of them you call processEvents() 10 times fewer for the same responsiveness. So if you have a lot of points you could sample or average and it would all be a lot quicker. Though that's probably very naughty :)

                        E 1 Reply Last reply 5 Jul 2018, 19:35
                        0
                        • J JonB
                          5 Jul 2018, 19:14

                          @engsml
                          300k points-odd is still a lot of points, though having no experience I don't know what to expect. I don't suppose your average end-user will notice each one of those. If you only add 1 in 10 of them you call processEvents() 10 times fewer for the same responsiveness. So if you have a lot of points you could sample or average and it would all be a lot quicker. Though that's probably very naughty :)

                          E Offline
                          E Offline
                          engsml
                          wrote on 5 Jul 2018, 19:35 last edited by
                          #21

                          @JonB That's definitely a good point. I'll have to play around with the UX when I get everything working properly in the end :)

                          J 1 Reply Last reply 5 Jul 2018, 19:40
                          0
                          • E engsml
                            5 Jul 2018, 19:35

                            @JonB That's definitely a good point. I'll have to play around with the UX when I get everything working properly in the end :)

                            J Offline
                            J Offline
                            JonB
                            wrote on 5 Jul 2018, 19:40 last edited by JonB 7 May 2018, 19:41
                            #22

                            @engsml
                            I see there is a https://doc.qt.io/qt-5.9/qxyseries.html#append-2 which takes a QList<QPointF>. It may or may not be more efficient than you adding points one-at-a-time. Might be worth a try?

                            E 1 Reply Last reply 6 Jul 2018, 14:05
                            0
                            • J JonB
                              5 Jul 2018, 16:05

                              @engsml
                              Hang on a minute. Let's look at your code, please:

                              int arrSize = 4096; //for incrementing in intervals
                              for(int i = 0; i < arr.size(); i += arrSize) //Plots in increments of 4096
                                  plot(arr, (i + 4096));
                              

                              This passes first 0+4096, then 4096+4096, then 8192+4096, then....

                              void myClass::plot(QVector<QPointF> arr, int size)
                                  for(int i = begin; i < size; i++){
                              

                              arr is always the original array. I presume (I'm not C++) begin is always 0. size is bigger (by 4096) every time plot is called.

                              Aren't you (re-)plotting more & more points --- specifically, all points from 0 up to where you have progressed to --- every time you call plot() in your batches?? Or am I going loopy?

                              S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 5 Jul 2018, 20:19 last edited by
                              #23

                              Hi,

                              @JonB said in GUI events slow down long computations:

                              void myClass::plot(QVector<QPointF> arr, int size)
                              for(int i = begin; i < size; i++){

                              arr is always the original array. I presume (I'm not C++) begin is always 0. size is bigger (by 4096) every time plot is called.

                              Nope, it's a copy, if you want to avoid useless copies, pass const references i.e. void myClass::plot(const QVector<QPointF> &arr).

                              In the case you only want to process items between two elements of the vector then pass the start and end iterator within your arrays.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              6
                              • J JonB
                                5 Jul 2018, 19:40

                                @engsml
                                I see there is a https://doc.qt.io/qt-5.9/qxyseries.html#append-2 which takes a QList<QPointF>. It may or may not be more efficient than you adding points one-at-a-time. Might be worth a try?

                                E Offline
                                E Offline
                                engsml
                                wrote on 6 Jul 2018, 14:05 last edited by
                                #24

                                @JonB I tried that, but it still caused the GUI to become unresponsive. I also tried a similar approach where I passed a QVector<QPointF> and did series->replace(); and that was also too slow for the function to handle. It seems the data is just too large for these functions. I considered passing the array in intervals instead of all at once for these functions, but ultimately decided it was already very similar to the function I already have.

                                1 Reply Last reply
                                1

                                19/24

                                5 Jul 2018, 18:58

                                • Login

                                • Login or register to search.
                                19 out of 24
                                • First post
                                  19/24
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved