Notifications
Clear all

[Closed] Progressbar performance

How would you guys make this work faster? The loading bar / Progress Bar is cutting performance roughly in half :


  rollout testRollz "Loading..." width:260 height:100 (
  	label lbl_infoA 		"Reading Files..."	pos:[11,20]
  	label lbl_infoB 		"Press ESC to cancel"	pos:[150,20]
  	progressbar mahprogbar color:green
  	button btn_Start 		"start loop" 		pos:[50,60] width:155 height:30
  	
  	on btn_Start pressed do (
  		maxSize = 10000000
  		for tmp=0 to maxSize do (
  			tmp += 1
  			if mahprogbar.value != (floor((tmp*100)/maxsize)) do (
  				mahprogbar.value = floor((tmp*100)/maxsize)
  				windows.processPostedMessages() --So Windows doesn't assume Max is 'Not Responding'
  			)
  			if keyboard.escPressed do (destroyDialog testRollz ; return "canceled")
  		)
  		--destroyDialog testRollz
  	)
  )
  createdialog testRollz
1 Reply

The slowdown is not necessarily due to accessing the progressbar value…the slowdown is happening because you’re doing 10 million iterations of a loop using maxscript Just try removing the progressbar code and replacing it with virtually anything else…you’ll get a similar speed hit. Maxscript is a slow language.

Btw you can simplify your code by using the modulus operator to check whether or not to update the progress bar. This will run slightly faster than the code you have now, but it won’t shave half the time off like removing all updates to the progress bar will.


   if mod tmp 100000 == 0 then
   (
   	 mahprogbar.value = ((tmp as float)/maxsize)*100				
   )
  
   

Also, processing windows messages while running slow code is almost always a bad idea and can lead to instability if the user does something in the max UI that interferes with the execution of your script. A better idea is to disable windows ghosting entirely. More info here.