Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Moved] Timer used to repaint (advance) delayed by event flood processing
Forum Updated to NodeBB v4.3 + New Features

[Moved] Timer used to repaint (advance) delayed by event flood processing

Scheduled Pinned Locked Moved Mobile and Embedded
46 Posts 7 Posters 26.2k Views 1 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.
  • D Offline
    D Offline
    DenisKormalev
    wrote on last edited by
    #17

    peppe, forum is "try this thing" at 85% of questions.
    dflorin, try to count how often paintEvent is invoked. If it invoked in good frequency then using background thread will help.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #18

      [quote]peppe, forum is “try this thing” at 85% of questions. [/quote]
      This dramatically makes a forum a low-quality forum.

      Still, after 10 posts, noone managed to explain me WHY your suggestion should work.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #19

        peppe, I don't know forum where you can ask any question you have stucked with and receive answer correctly and quickly. And this discussion is offtopic. If you have something to add about subj of topic then add.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dflorin
          wrote on last edited by
          #20

          Back to the subject. I made some measurements:

          When not moving the bat:

          • Bat::paint() called 30 times (how many times the bat is repainted as a result of setPos() called from the event() method)
          • Ball::advance() called 30 times (this is called by the timer and should be 30 calls instead) - this will trigger paint()

          NOTE: the Bat is also repainted because I use:
          view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
          This should not have any impact on my problem.

          When moving the bat as fast as I can using touch events:

          • Scene::event() called 47 times (this is how fast I move the bat by touching the screen)
          • Bat::paint() called 50 times (how many times the bat is repainted as a result of setPos() called from the event() method and as a result of paint() done for the ball)
          • Ball::advance() called 13 times (this is called by the timer and should be 30 calls instead) - this is my problem: the ball has slowed down at less than half speed.

          And one more thing: this is noticeable on a Symbian device. Running it in the simulator on Windows and using mouse events instead of touch events does not slow down the ball. Should the post be moved to Mobile and Embedded?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on last edited by
            #21

            dflorin, looking at this measurement I think it is worth to try moving ball coordinates calculation into another thread.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dflorin
              wrote on last edited by
              #22

              [quote author="Denis Kormalev" date="1293490361"]dflorin, looking at this measurement I think it is worth to try moving ball coordinates calculation into another thread.[/quote]

              Even if the advance() only does x=x+1?

              Please note my comment related to reproducibility on Symbian only.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DenisKormalev
                wrote on last edited by
                #23

                dflorin, problem is not in calculation complexity, problem is in a big count of mouse and paint events which don't allow your timer to work in needed frequency.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dflorin
                  wrote on last edited by
                  #24

                  Ok, thanks. I will try that and get back with the result.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #25

                    But what is done inside this events.

                    If I countthe events you tell, it is about 110 evnts, that's not much work. But what is done inside Scene::event? Why is bat painted 50 times? that means 50 times a complete viewport repaint? That is overhead.

                    If Ball::advance initiates an update, which results in a full repaint, that means in your example 63 times a full repaint with all items / elemnts. I'm not sure how fast you processor is (as it's an embedded device I think). On a PC, it wouldn't be problematic.

                    What do you do in the touch events? Is this time consuming?

                    All this were just ideas, that came into my mind.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #26

                      On one of the last DevDays there was talk about speeding up QGraphicsView. Here are some of the presentations that might help you:

                      "Graphics View (2007) ":http://qt.nokia.com/developer/learning/online/talks/archive/developerdays2007/graphics-view
                      "Optimizing Performance in Qt-Based Applications (2009) ":http://qt.nokia.com/developer/learning/online/talks/developerdays2009/tech-talks/optimizing-performance-in-qt-based-applications
                      "Beautiful and Blazing-Fast Graphics with Qt (2008) ":http://qt.nokia.com/developer/learning/online/talks/archive/developerdays2008/beautiful-and-blazing-fast-graphics-with-qt

                      I did not review the videos, so it could also be that they fail the topic completely.

                      I do remember that some issues can be solved by setting the proper caching strategy to avoid complete repaints of the graphics scene.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        DenisKormalev
                        wrote on last edited by
                        #27

                        Gerolf is right, full repaint is an overhead. Maybe you can try to make partial repaints (where it is needed)?

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dangelog
                          wrote on last edited by
                          #28

                          [quote author="dflorin" date="1293490166"]
                          When moving the bat as fast as I can using touch events:

                          • Scene::event() called 47 times (this is how fast I move the bat by touching the screen)
                          • Bat::paint() called 50 times (how many times the bat is repainted as a result of setPos() called from the event() method and as a result of paint() done for the ball)
                          • Ball::advance() called 13 times (this is called by the timer and should be 30 calls instead) - this is my problem: the ball has slowed down at less than half speed.
                            [/quote]

                          Are these values per second? Can you monitor the CPU usage while moving the bat and/or profile? This doesn't seem to be a flood of events (47+50+13 = 120), rather it seems you're wasting CPU somewhere (for processing events, drawing, etc.) and not returning to the event loop so often like you should; especially, a full viewport update seems to be an overkill. Is there any reason why you chose to do so?

                          [quote] And one more thing: this is noticeable on a Symbian device. Running it in the simulator on Windows and using mouse events instead of touch events does not slow down the ball. Should the post be moved to Mobile and Embedded?[/quote]

                          Perhaps the Symbian device hasn't the needed CPU power, or there's a bug somewhere. I'll leave the decision about moving the post to admins :-)

                          Software Engineer
                          KDAB (UK) Ltd., a KDAB Group company

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #29

                            As Volker told, there were topics on repainting the QGraphicsView, also on 2010. They showed the difference between Raster painting, open GL etc. I think, it was this:

                            "Performance: Do Graphics the Right Way ":http://qt.nokia.com/developer/learning/online/talks/developerdays2010/tech-talks/performance-do-graphics-the-right-way

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #30

                              YESSS! Gerolf, you are a truffle pig :-)

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                DenisKormalev
                                wrote on last edited by
                                #31

                                [quote author="peppe" date="1293492647"]
                                Perhaps the Symbian device hasn't the needed CPU power, or there's a bug somewhere. I'll leave the decision about moving the post to admins :-)[/quote]

                                I'll leave it here for some time. Maybe some Troll can confirm that it is related only to mobile (or even only to symbian).

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dflorin
                                  wrote on last edited by
                                  #32

                                  Some more measurements.

                                  This is how it looks before moving the bat:

                                  bq. [Qt Message] "13:29:53.620" Scene::event() ENTER
                                  [Qt Message] "13:29:53.621" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.624" Bat::paint() - paintCount: 63
                                  [Qt Message] "13:29:53.627" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.630" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.647" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.649" Ball::advance() - advanceCount: 63
                                  [Qt Message] "13:29:53.650" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.652" Scene::event() ENTER
                                  [Qt Message] "13:29:53.653" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.656" Bat::paint() - paintCount: 64
                                  [Qt Message] "13:29:53.660" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.663" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.678" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.680" Ball::advance() - advanceCount: 64
                                  [Qt Message] "13:29:53.681" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.683" Scene::event() ENTER
                                  [Qt Message] "13:29:53.684" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.688" Bat::paint() - paintCount: 65
                                  [Qt Message] "13:29:53.692" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.695" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.711" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.713" Ball::advance() - advanceCount: 65
                                  [Qt Message] "13:29:53.714" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.716" Scene::event() ENTER
                                  [Qt Message] "13:29:53.718" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.722" Bat::paint() - paintCount: 66
                                  [Qt Message] "13:29:53.725" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.728" Ball::paint() EXIT

                                  This is how it looks after I start touching the screen and moving the bat as fast as I can:

                                  bq. Qt Message] "13:29:53.732" Scene::event() ENTER
                                  [Qt Message] "13:29:53.733" Scene::event() - touchCount: 1
                                  [Qt Message] "13:29:53.737" Scene::event() EXIT - touch event processed
                                  [Qt Message] "13:29:53.738" Scene::event() ENTER
                                  [Qt Message] "13:29:53.740" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.742" Scene::event() ENTER
                                  [Qt Message] "13:29:53.744" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.746" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.748" Ball::advance() - advanceCount: 66
                                  [Qt Message] "13:29:53.751" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.753" Scene::event() ENTER
                                  [Qt Message] "13:29:53.754" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.757" Bat::paint() - paintCount: 67
                                  [Qt Message] "13:29:53.760" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.763" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.778" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.780" Ball::advance() - advanceCount: 67
                                  [Qt Message] "13:29:53.783" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.785" Scene::event() ENTER
                                  [Qt Message] "13:29:53.786" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.789" Bat::paint() - paintCount: 68
                                  [Qt Message] "13:29:53.791" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.794" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.809" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.812" Ball::advance() - advanceCount: 68
                                  [Qt Message] "13:29:53.815" Ball::advance() - EXIT
                                  [Qt Message] "13:29:53.816" Scene::event() ENTER
                                  [Qt Message] "13:29:53.818" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.821" Bat::paint() - paintCount: 69
                                  [Qt Message] "13:29:53.824" Ball::paint() ENTER
                                  [Qt Message] "13:29:53.827" Ball::paint() EXIT
                                  [Qt Message] "13:29:53.838" Scene::event() ENTER
                                  [Qt Message] "13:29:53.840" Scene::event() - touchCount: 2
                                  [Qt Message] "13:29:53.842" Scene::event() EXIT - touch event processed
                                  [Qt Message] "13:29:53.846" Scene::event() ENTER
                                  [Qt Message] "13:29:53.848" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.851" Scene::event() ENTER
                                  [Qt Message] "13:29:53.852" Scene::event() - touchCount: 3
                                  [Qt Message] "13:29:53.854" Scene::event() EXIT - touch event processed
                                  [Qt Message] "13:29:53.855" Scene::event() ENTER
                                  [Qt Message] "13:29:53.857" Scene::event() EXIT - NO touch event
                                  [Qt Message] "13:29:53.858" Ball::advance() - ENTER
                                  [Qt Message] "13:29:53.860" Ball::advance() - advanceCount: 69
                                  [Qt Message] "13:29:53.862" Ball::advance() - EXIT

                                  As you can see from the traces, when no touch, the interval between 2 consecutive advance() calls is 30ms. After the first touch it raises to 49ms while touch 2 and 3 are processed.

                                  Here is the processing inside the event() method:

                                  @bool MyGraphicsScene::event(QEvent *event)
                                  {
                                  qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() ENTER";
                                  switch (event->type()) {
                                  case QEvent::TouchBegin:
                                  case QEvent::TouchUpdate:
                                  case QEvent::TouchEnd:
                                  {
                                  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);

                                          if (touchEvent->touchPoints().count() == 1) {
                                              const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
                                  
                                              QGraphicsItem *bat = items().at(4);
                                              qreal p = touchPoint1.scenePos().y();
                                              qreal lp = touchPoint1.lastScenePos().y();
                                              qreal dY = p - lp;
                                              bat->setPos(bat->pos().x(), bat->pos().y() + dY/4);
                                          }
                                  
                                          break;
                                      }
                                  
                                      default:
                                          qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() EXIT - NO touch event";
                                          return QGraphicsScene::event(event);
                                  }
                                  
                                  touchCount++;
                                  qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() - touchCount: " << touchCount;
                                  qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "Scene::event() EXIT - touch event processed";
                                  
                                  return true;
                                  

                                  }@

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    goetz
                                    wrote on last edited by
                                    #33

                                    I've moved the thread to the Mobile and Embedded forum, as the problem only occurs on the Symbian platform.

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      dangelog
                                      wrote on last edited by
                                      #34

                                      As I said, profile the CPU usage. Is OpenGL somehow involved?

                                      Software Engineer
                                      KDAB (UK) Ltd., a KDAB Group company

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        giesbert
                                        wrote on last edited by
                                        #35

                                        If you look at the time, needed in the events:

                                        bq. [Qt Message] “13:29:53.620” Scene::event() ENTER
                                        [Qt Message] “13:29:53.621” Scene::event() EXIT – NO touch event

                                        bq. Qt Message] “13:29:53.732” Scene::event() ENTER
                                        [Qt Message] “13:29:53.733” Scene::event() – touchCount: 1
                                        [Qt Message] “13:29:53.737” Scene::event() EXIT – touch event processed
                                        [Qt Message] “13:29:53.738” Scene::event() ENTER
                                        [Qt Message] “13:29:53.740” Scene::event() EXIT – NO touch event

                                        So in case of touch, it takes 7 msecs, otherwise 1 msec.
                                        As it seams, there are more events, it would be interesting, which type of evenmts come in.

                                        what I also saw, was:

                                        bq. [Qt Message] “13:29:53.746” Ball::advance() – ENTER
                                        [Qt Message] “13:29:53.778” Ball::advance() – ENTER
                                        [Qt Message] “13:29:53.809” Ball::advance() – ENTER
                                        [Qt Message] “13:29:53.858” Ball::advance() – ENTER

                                        it's only one advance call that is delayed. And if your touch event takes 7 msecs, and you get 2 or three of them, that is 14 to 21 msecs.

                                        So, my next try would be check the event types of the events, that come in at Scene::event() ( as there are more than without touch that are not touch).

                                        Reduce amount of data to redraw.

                                        Nokia Certified Qt Specialist.
                                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          giesbert
                                          wrote on last edited by
                                          #36

                                          Aditionally, painting the ball takes 4 msecs, painting the bat also takes ??? (I think 2 - 3 msecs, from the trace).

                                          Nokia Certified Qt Specialist.
                                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                          1 Reply Last reply
                                          0

                                          • Login

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