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. Improving performance
Forum Updated to NodeBB v4.3 + New Features

Improving performance

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.0k Views 3 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    Presently I have an instance of QTimer that is set to 1ms, this is used to trigger processing of a large file, however its not fast enough and takes to long, each iteration of the timeout signal triggers processing of a section of the file, this continues until the entire file has been processed.

    I thought I would try an improve on the time it takes to process the file by doing away with the timer and instead emitting a signal at the end of the processing, so the last line of the slot triggers the signal again, this doesn't work and I get a stack overflow.

    Is there a better way to prove on the performance with a higher resolution timer or alternative?

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      Presently I have an instance of QTimer that is set to 1ms, this is used to trigger processing of a large file, however its not fast enough and takes to long, each iteration of the timeout signal triggers processing of a section of the file, this continues until the entire file has been processed.

      I thought I would try an improve on the time it takes to process the file by doing away with the timer and instead emitting a signal at the end of the processing, so the last line of the slot triggers the signal again, this doesn't work and I get a stack overflow.

      Is there a better way to prove on the performance with a higher resolution timer or alternative?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SPlatten said in Improving performance:

      the last line of the slot triggers the signal again, this doesn't work and I get a stack overflow.

      Sounds like infinite loop, leading to stack overflow.
      Why do you emit SAME signal?
      Why don't you simply add another signal which is emitted at the end of processing?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @SPlatten said in Improving performance:

        the last line of the slot triggers the signal again, this doesn't work and I get a stack overflow.

        Sounds like infinite loop, leading to stack overflow.
        Why do you emit SAME signal?
        Why don't you simply add another signal which is emitted at the end of processing?

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #3

        @jsulm I'm really just looking for a way to trigger processing fast and efficient without locking up the GUI, I need a way to trigger processing of the file in chunks and the current implementation is just to slow. There is already another signal emitted when the processing is finished, the signal thats causing the stack overflow is a signal to continue processing.

        Kind Regards,
        Sy

        jsulmJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @jsulm I'm really just looking for a way to trigger processing fast and efficient without locking up the GUI, I need a way to trigger processing of the file in chunks and the current implementation is just to slow. There is already another signal emitted when the processing is finished, the signal thats causing the stack overflow is a signal to continue processing.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @SPlatten Do you want to process these chunks in parallel or serial?
          If serial: use same signal, but add a break condition (if last chunk -> do not emit signal).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          SPlattenS 1 Reply Last reply
          0
          • jsulmJ jsulm

            @SPlatten Do you want to process these chunks in parallel or serial?
            If serial: use same signal, but add a break condition (if last chunk -> do not emit signal).

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #5

            @jsulm, presently the application isn't doing much whilst the file is processed, there is a dialog displayed which shows the status and progress, so the user knows that something is being done.

            I will try using a thread to solve the problem.

            Kind Regards,
            Sy

            jsulmJ 2 Replies Last reply
            0
            • SPlattenS SPlatten

              @jsulm, presently the application isn't doing much whilst the file is processed, there is a dialog displayed which shows the status and progress, so the user knows that something is being done.

              I will try using a thread to solve the problem.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @SPlatten Doesn't answer my question.
              There is one more thing to consider: by default DirectConnection is used for signal/slot connections in same thread. That means: an emit is nothing more than a method call and if you emit same signal from the slot you basically have recursive function. If you have too many iterations you will get stack overflow. You can try to use QueuedConnection when calling connect.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • SPlattenS SPlatten

                @jsulm, presently the application isn't doing much whilst the file is processed, there is a dialog displayed which shows the status and progress, so the user knows that something is being done.

                I will try using a thread to solve the problem.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @SPlatten But actually you should move heavy operations to another thread to not to block main thread.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  SimonSchroeder
                  wrote on last edited by
                  #8

                  The best approach to use a QTimer is to set a timeout of 0ms. This way the timeout will be handled when the event loop is idle (not immediatly). A better way is to use a separate thread as the others already mentioned.

                  SPlattenS 1 Reply Last reply
                  0
                  • S SimonSchroeder

                    The best approach to use a QTimer is to set a timeout of 0ms. This way the timeout will be handled when the event loop is idle (not immediatly). A better way is to use a separate thread as the others already mentioned.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #9

                    @SimonSchroeder, I've now moved to a separate thread which is so much faster than the timer could ever be on Windows.

                    Kind Regards,
                    Sy

                    jeremy_kJ 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @SimonSchroeder, I've now moved to a separate thread which is so much faster than the timer could ever be on Windows.

                      jeremy_kJ Offline
                      jeremy_kJ Offline
                      jeremy_k
                      wrote on last edited by
                      #10

                      @SPlatten said in Improving performance:

                      @SimonSchroeder, I've now moved to a separate thread which is so much faster than the timer could ever be on Windows.

                      Not using an event loop will be faster than using an event loop. Not calling a function will be faster than calling a function. Not context switching and data synchronizing will be faster than context switching and data synchronizing.

                      At a glance, the Windows zero timer implementation doesn't use an OS timer facility.

                      Asking a question about code? http://eel.is/iso-c++/testcase/

                      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