Hi,
I have an app with many graphs that are all redrawn 24 times per second. I would like to measure how much time is spent in the drawFuncs of my various UserViews, and add up all those times. So, is UserView.refresh synchronous or asynchronous, i.e., when it returns, can I be confident that the UserView has been redrawn or not? If it is synchronous, then I know what to do. If it is not, is there some flag or hook in the system that tells me that all Views have been redrawn and that no refreshes are outstanding?
I thought that this might qualify as a Development topic since it would help us to write smarter drawing functions. Any insights would be welcome!
Would Function;bench
suffice? You can disable the printing and it returns the time taken.
UserView:refresh
is synchronous, so checking the clock (or Function:bench
as @jordan suggested) should work. Drawing functions are somewhat decoupled from actual drawing on-screen, so the only “queue” / outstanding draws are really what you have created for yourself - if you’re calling refresh
24 times a second, all the draw calls are complete once you’ve finished calling all the refresh
methods.
You can automate updates using the View:animate
property (which makes it harder to determine when draw calls happen…), but this is functionally identical to just calling refresh functions yourself 24 times a second on the AppClock. So, one approach might be to skip animate
, stick all of your views in a list, and then call refresh
on them yourself and measure the overall time. For example, something like -
~views = [];
~addView = { |view| ~views = ~views.add(view) };
~removeView = { |view| ~views.remove(view) };
SkipJack({
{
~views.do(_.refresh)
}.bench
}, 1/24);
Thanks both for your input, very helpful!
In the end, I put calls to Main.elapsedTime just before and after the GUI refresh cycle (for lots of views), with a one-second FIFO buffer, and that works. This little meter shows the redraw activity, scrolling vertically, for the past second, as I vigorously resize the main window:
The numbers are average and peak percentages of the CPU time used during each 1/24 second, for the past second, i.e., with 24 refresh cycles. I put this in as an optional diagnostic, because on slow machines (battery saving), or when screen-sharing in video calls, the computer doesn’t always keep up.