Don't use progress dialog with large data

Don't use progress dialog with large data

JeromeBriot
Mentor Mentor
776 Views
2 Replies
Message 1 of 3

Don't use progress dialog with large data

JeromeBriot
Mentor
Mentor

Hello,

 

I already faced this issue with other languages so I don't call this a bug.  I just want to warn people about this behavior.

 

Here is a code that runs two empty loops:

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

import time

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        elapsedTime = [0.0, 0.0]

        N = 25000

        progressDialog = ui.createProgressDialog()
        progressDialog.cancelButtonText = 'Cancel'
        progressDialog.isBackgroundTranslucent = False
        progressDialog.isCancelButtonShown = True
        progressDialog.hide()

        progressDialog.show('Speed test', 'Percentage: %p, Current Value: %v, Total steps: %m', 0, N)

        startTime = time.time()

        for i in range(0, N):

            if progressDialog.wasCancelled:
                break

            progressDialog.progressValue = i

            pass

        elapsedTime[0] = time.time() - startTime

        progressDialog.hide()

        startTime = time.time()

        for i in range(0, N):

            pass

        elapsedTime[1] = time.time() - startTime

        ui.messageBox('{:.1f} s\n{:.1f} s'.format(elapsedTime[0], elapsedTime[1]))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Now the results on my PC (i7-3700) for 25000 iterations:

  • First loop with the progress dialog: 13.2s
  • Second loop without the progress dialog: 0.0s

It's even worst on my Mac (i5-3210M):

  • First loop with the progress dialog: 208s
  • Second loop without the progress dialog: 0.0s

More results from a code in which I export mesh data to STL file with and without the progress dialog.

 

On my PC:

  • Low mesh refinement (3900 iterations): 2.0s / 0.0s
  • Normal mesh refinement (9000 iterations): 4.6s / 0.1s
  • High mesh refinement (26000 iterations): 13.1s / 0.3s
  • Very High mesh refinement (89600 iterations): 45.6s / 0.9s

Same results on my Mac:

  • Low mesh refinement (3900 iterations): 32s / 0.0s
  • Normal mesh refinement (9000 iterations): 75s / 0.1s
  • High mesh refinement (26000 iterations): 216s / 0.2s
  • Very High mesh refinement (89600 iterations): 745 / 0.8s

The progress dialog costs 0.0005 second per iteration on my PC and 0.008 second per iteration on my Mac.

 

Now you know!

 

777 Views
2 Replies
Replies (2)
Message 2 of 3

markER7TS
Contributor
Contributor

Maybe you could have the best of both worlds if you modulo divide your operation count and only update the UI every few thousand loops?

0 Likes
Message 3 of 3

jackie.lin.945
Participant
Participant

Thank you for the information.

0 Likes