Computer Science Canada

Never Use View.Update

Author:  copthesaint [ Mon Feb 09, 2009 8:43 am ]
Post subject:  Never Use View.Update

While Programing I stummbled across a Program That uses View.Update And View.UpdateArea.
I decided I will change The program around and I had learnt from this.
Useing
code:
View.UpdateArea (0,0,Maxx,Maxy)

Can Increase your Program Speed By up to 25% (larger the program smaller the increase)
So instead of
code:
View.Update

Use
code:
View.UpdateArea (0,0,Maxx,Maxy)


Here Is my program that proves this.
You will get Different Results Everytime. (smaller the Maple leaf, Faster the animation)

Author:  DemonWasp [ Mon Feb 09, 2009 9:29 am ]
Post subject:  RE:Never Use View.Update

Though your code is a bit off, your conclusion seems valid. Where you're computing how much faster, you should have:
code:
NumResult := realstr ( num3 / num1 * 100 - 100, 0 )

Alternately, you could substitute num2 for num3 there.

It makes perfect sense to me that updating only a portion of the screen should be faster, but I'm confused - why would updating the entire screen using UpdateArea() be faster than just Update() ?

Author:  copthesaint [ Mon Feb 09, 2009 10:21 am ]
Post subject:  RE:Never Use View.Update

Maybe Because View.Update Usese a procedure that is more line then View.UpdateArea. Beace you are Supplieing The X,Y,X2,Y2 positions maybe. All I know That is It's faster And Can increase your programs speed, and the Program clearly proves that it is faster.

Author:  SNIPERDUDE [ Mon Feb 09, 2009 2:31 pm ]
Post subject:  RE:Never Use View.Update

Wow, this is actually an incredible find. Many thanks

Author:  Tony [ Mon Feb 09, 2009 3:57 pm ]
Post subject:  Re: Never Use View.Update

A problem with this test is that Time measured as a resolution of a second, out of 5 seconds, could introduce an error of up to 1 second in size (if a test starts at the end of a second), which would randomly give a 1/5 = 20% difference. I found the results to vary greatly (which should have been a clue that there's a problem), and I've even gotten a negative result.

A better idea is to use Time.Elapsed, timing to 5000 milliseconds. The results were much more consistent, hovering at about 8 +/-1 %; using DemonWasp's NumResult.

Which makes sense, because you are updating a smaller area.

The View.UpdateArea (0,0,Maxx,Maxy) is at 0 +/- 1 %; often in the negatives.

Author:  DemonWasp [ Mon Feb 09, 2009 4:47 pm ]
Post subject:  RE:Never Use View.Update

Ah, cleverly done, Tony. I was getting slightly concerned that perhaps I'd descended into some sort of chaotic nonsense world where updating the whole screen was slower than updating the whole screen.

Author:  saltpro15 [ Mon Feb 09, 2009 5:39 pm ]
Post subject:  RE:Never Use View.Update

well I'll be damned... that is the best post I have ever read, thanks a lot man, helps SO much in my game, went from 8 fps to 13 fps

Author:  Clayton [ Mon Feb 09, 2009 7:58 pm ]
Post subject:  RE:Never Use View.Update

I would have thought this would have been fairly obvious. Double buffering a fraction of the screen is faster than double buffering the whole screen? Less work means more speed (Note: This does not mean that Update() has more LoC (Lines of Code) than UpdateArea()). If someone had read my tutorial in the Turing Walkthrough, one would (should, anyways) know this.

Author:  Insectoid [ Mon Feb 09, 2009 8:12 pm ]
Post subject:  RE:Never Use View.Update

I think the point is that View.UpdateArea (0, 0, maxx, maxy), which does buffer the whole screen, is faster than View.Update, which also updates the whole screen.

Author:  Clayton [ Mon Feb 09, 2009 8:14 pm ]
Post subject:  RE:Never Use View.Update

insectoid wrote:
I think the point is that View.UpdateArea (0, 0, maxx, maxy) ... is faster than View.Update ...
Tony wrote:
The View.UpdateArea (0,0,Maxx,Maxy) is at 0 +/- 1 %; often in the negatives.


Not by much. If at all.

Author:  mirhagk [ Tue Dec 15, 2009 12:28 pm ]
Post subject:  RE:Never Use View.Update

To be honest I'm a little confused by all of this, so changing from View.Update to View.UpdateArea(0,0,maxx,maxy) doesn't really help??

Also would it be better to use View.UpdateArea right after I draw every object?? (as long as I don't have to many objects that overlap)

Author:  DemonWasp [ Tue Dec 15, 2009 1:13 pm ]
Post subject:  RE:Never Use View.Update

No and no, respectively.

Author:  mirhagk [ Tue Dec 15, 2009 2:03 pm ]
Post subject:  RE:Never Use View.Update

why wouldn't it be?? it would update only the parts of the screen that have changed

Author:  DemonWasp [ Tue Dec 15, 2009 2:39 pm ]
Post subject:  RE:Never Use View.Update

Yes, but assuming you're updating any sizeable portion of the screen, the overhead of updating many areas of the screen independently of each other would likely dwarf the overhead of updating areas of the screen that may not need updating. Imagine the extreme case: 1 call to View.Update() to update the entire screen, or maxx*maxy updates to update individual pixels. Which would be faster? Obviously the first. There are situations where you could get a targeted View.UpdateArea to perform better, but not if you update any portion of the screen with regularity (such as moving the view around a map, for example).

Author:  mirhagk [ Tue Dec 15, 2009 3:00 pm ]
Post subject:  RE:Never Use View.Update

yeah of course if I have a lot of objects that are changing on screen, but I meant if I have for instance a mario game (where the background picture remains the same)

All i'd be updating is the tiles and mario so would it run faster than View.Update

Author:  DemonWasp [ Tue Dec 15, 2009 4:16 pm ]
Post subject:  RE:Never Use View.Update

Mario's background scrolls past him, does it not?

Author:  mirhagk [ Wed Dec 16, 2009 8:09 am ]
Post subject:  RE:Never Use View.Update

no i said where the background remains the same. Kinda like a static background image or even just a blank black background or something

Author:  Tyr_God_Of_War [ Wed Feb 10, 2010 4:29 pm ]
Post subject:  RE:Never Use View.Update

But the area behind where Mario was needs updating as well. Make sure to keep track of that.

Author:  evildaddy911 [ Sat Jan 07, 2012 11:13 am ]
Post subject:  Re: Never Use View.Update

on the same note, Time.DelaySinceLast() is slightly better than Time.Delay() or delay(), delay() causes a delay no matter what, while Time.DelaySinceLast() only delays if it is needed, and only as much as is needed, causing most lag to disappear.

Author:  Dreadnought [ Sat Jan 07, 2012 5:38 pm ]
Post subject:  Re: Never Use View.Update

@ evildaddy911

1 - Your necroing.
2 - Time.DelaySinceLast is not "slightly better" than Time.Delay. Rather its functionality (which is different from Time.Delay) is more useful in common situations (namely animation). It should not be regarded as a direct substitute for Time.Delay.


: