Progress hangs briefly in debugging mode

Toying with progress more, and I notice that in this script, if I have debugging on, when I run it SD hangs with the swirly rainbow cursor for a few seconds and then the progress pane starts up at 6 or 7. If I turn off debugging it behaves normally, if I turn debugging back on it works normally too, but if I recompile the hang returns.

my updateProgress({ProgressTotalSteps:10, ProgressCompletedSteps:0, ProgressDesc:"Testing progress", ProgressExtraDesc:"Starting Up"})
delay 2
repeat with progressCounter from 1 to 10
   delay 1
   my updateProgress({ProgressCompletedSteps:progressCounter, ProgressExtraDesc:"Step " & progressCounter as text})
end repeat

on updateProgress(progressRecord)
   local progressRecord, totalSteps, completedSteps, desc, extraDesc
   --{ProgressTotalSteps: 10,ProgresscompletedSteps:1, ProgressDesc:"", ProgressExtraDesc:"" )
      set totalSteps to ProgressTotalSteps of progressRecord
   on error
      set totalSteps to ""
   end try
      set completedSteps to ProgressCompletedSteps of progressRecord
   on error
      set completedSteps to ""
   end try
      set desc to ProgressDesc of progressRecord
   on error
      set desc to 0
   end try
      set extraDesc to ProgressExtraDesc of progressRecord
   on error
      set extraDesc to 0
   end try
   if totalSteps is not "" then set progress total steps to totalSteps
   if completedSteps is not "" then set progress completed steps to completedSteps
   if desc is not 0 then set progress description to desc
   if extraDesc is not 0 then set progress additional description to extraDesc
end updateProgress


I would expect there to be a 3 second pause because of the delay 2 and the delay 1 statements before the first progress indication appears. While AppleScript is executing a delay statement, everything is blocked, and in the case if this script, the progress completed steps property is not altered until both the delay 2 and delay 1 statements have been executed.

OK, so the first line executes and we should see the progress pane with an empty circle, then a two-second delay.

Then it jumps into the repeat loop and we have another delay.

Then the update line in the repeat loop executes and we should see the pane update with 1 step, and the same for each iteration of the loop.

Instead, what happens is the script starts, I get the swirly rainbow cursor, and after about 5 seconds the progress pane appear and it’s already on 6 or 7.