|
-
Oct 15th, 2020, 11:17 AM
#1
[RESOLVED] The Cost of Refreshing
This comes from an XNA/MonoGame specific question, which isn't something folks here seem to deal with all that much, but the underlying question has more to do with Windows and hardware than any specific language or technology, so there may be some insight from this group.
I have a project that draws controls using XNA. While doing some profiling in a test app, I realized something interesting: I was paying a cost of 17ms every time I refreshed a control, but this was not a per control cost. For example, I had this test loop:
Code:
Private Sub Test1()
For x = 0 To 10
mTestControl.Refresh()
mTestControl2.Refresh()
Next
End Sub
It didn't matter whether I had two controls being refreshed or just one, the cost was always the same. Each control does some moderately intensive composition, but I was able to isolate that and time it to take about 0.01ms, or thereabouts. This would be paid per control, but the difference between 0.01 and 0.02ms was being lost in the noise of the fact that the method was taking roughly 17ms per iteration (plus or minus 2ms, which is why 0.01 was lost in the noise).
I then tried the same thing with a pair of standard WinForms buttons. These had a refresh cost of 0.5ms, or so, and that was per control, so refreshing two controls cost 0.1ms, and three would cost 0.15ms.
A per cost control makes plenty of sense, to me, and there is one both for the standard WinForms button (0.5ms) and my composed XNA control (0.01ms). But what was that one time 17ms that was getting paid for refreshing the XNA controls?
I commented out the whole body of that method, just to make sure that it WAS that code that was incurring the cost, and the cost dropped to 0, as it should (calling a function with no body takes virtually no time). I also changed the number of iterations from 10 to 1, then to 100. That had the impact expected. One iteration took 17ms (roughly), 10 took roughly 170ms, and 100 took roughly 1,700ms. These values remain the same whether I refresh one control or two.
I then doubled the number of refreshes a different way:
Code:
Private Sub Test1()
For x = 0 To 10
mTestControl.Refresh()
mTestControl2.Refresh()
mTestControl.Refresh()
mTestControl2.Refresh()
Next
End Sub
In other words, refresh each control twice. This doubled the cost to around 34ms. Commenting out both refreshes of mTestControl2 didn't change the cost at all.
This kind of rules out the improbable answer that the system recognized that the two controls were identical (they are, but they are not the same control, they just have the same appearance) and just copied the drawing of the first for the second.
I can't think of anything further to test. There's a cost for refreshing anything in XNA, and once you set out to refresh, it doesn't seem to matter how many things get refreshed.
Would anybody venture an explanation as to what one time cost I could be seeing?
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|