Announcement

Collapse
No announcement yet.

Cleaver, or Wasteful Programming?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cleaver, or Wasteful Programming?

    Others may have caught this before, but I just noticed what looks like either something cleaver or a serious case of wasteful, impolite programming. I just upgraded my system's memory (Athlon 900, Windows 2000, going from 256 megs to 768) and decided to look at the performance measurement display in the Win2K task manager to see whether it looks like the extra memory is making a difference. When I looked at the "CPU Usage" part of the dispaly, I got a surprise. Even now while I'm typing this on Internet Explorer, Civ 3 has my CPU utilization pegged at 100%, and the program is just waiting for me to hit Enter to end the turn. (CPU utilization is also maxed out during the turn, but it drops down a bit at times during the "new turn" routine when the CPU has to wait for other resources.)

    If the 100% CPU utilization reflects the AI thinking about strategy during the human player's turn, that might be regarded as a cleaver use of resources. But otherwise, it seems just plain sloppy. Windows operating systems are designed to support multitasking, and it's hard to find an excuse in this day and age for a professional development outfit's failing to recognize that someone might want to switch back and forth between their game and something else (like writing about their game?). But with Civ 3 always competing for CPU power, anything else running at the same time gets slowed down - a phenomenon I'd noticed before but hadn't realized was caused by something so obvious.

    By the way, I'm almost positive I was right that with Win2K, having more than 256 megs of RAM will come in pretty handy (and Windows XP would almost certainly be worse). Large-map games in the modern era can get in the 256 meg range all by themselves even without a lot of players, and huge maps could get worse. And even with standard maps, when I have Outlook Express, several Internet Explorer Windows, and maybe another thing or three running alongside Civ 3, 256 megs isn't enough to fit everything. (In the latter case, the main effect would probably be on the speed of switching between programs rather than on the speed a particular program runs at once it gets going, since Windows can swap to disk to pretend it has more memory than it really does.)

    Nathan

  • #2
    Clever, not cleaver. The post sounded so intriguing. I run Civ3 on XP with 128MB, and it gets pretty bad sometimes. Thankfully 512 are on their way. There is a lot you can do to tweak Xp and ME, to help with the performance on larger maps of Civ3.
    Rhett Monroe Chassereau

    "I use to be with it, then they changed what it is. And what I'm with isn't it, and what is it seems strange and scary to me." -Abe Simpson

    Comment


    • #3
      I do not know why, but most games show up at 100% on my XP PRO running on AMD 1900+. I think it is the use and control of the mouse/vid that makes the kernnel report it busy.

      Comment


      • #4
        Originally posted by vmxa1
        I do not know why, but most games show up at 100% on my XP PRO running on AMD 1900+. I think it is the use and control of the mouse/vid that makes the kernnel report it busy.
        Usually, that kind of behavior is due to "polling loops" where a program keeps asking "Has such-and-such happened yet?" as quickly as it can. Under some circumstances, such a loop might execute the same half dozen lines of code millions of times per second.

        I can even see some possible sense in using such an approach in fast-paced arcade (or some types of RTS) games where rapid response to user inputs is critical. If the operating system forces the designers to choose between waiting "too long" between polling cycles or not waiting at all, not waiting at all may be the best option.

        But in a game like Civ 3, unless the Windows 95/98/ME series is a lot more limited than I think it is, I see no good reason not to build in a delay of 1/100 of a second or so between loop cycles - especially after the game has been idle for a few seconds. In a turn-based game, that would still detect movement quickly enough to make the delay unnoticeable to human senses, but would reduce CPU utilization to near zero when the game is idle.

        Unfortunately, from what you've written, it sounds like a lot of game developers are either ignorant or apathetic regarding how to write a program to play nicely with others. Maybe too many of them got their start when they could pretty much count on having the whole system to themselves and they just haven't adjusted to the realities of modern hardware and operating systems yet. Fortunately for Firaxis, Civ 3 is good enough that I'm willing to tolerate poor marks in the "plays well with others" category.

        Nathan

        Comment


        • #5
          Civ2 behaved in the same manner, 100% CPU all the time.

          It could be doing something clever while it waits for a key-press but I doubt it.

          Most programmers learn the difference between constant polling and events within the first couple of minths at school.
          Don't eat the yellow snow.

          Comment


          • #6
            Originally posted by bongo
            Civ2 behaved in the same manner, 100% CPU all the time.
            I also notice that too. I usually run it on my laptop and it never power down to save battery when it's not being used.

            Comment


            • #7
              Note that it occurs even when I exit the game to the main menu? Several TBS games behave this for meon XP. I can not recall if that was the case in 98se.

              Comment


              • #8
                Send a little message to Firaxis asking why this is the case. If they can get it to Soren (and he is willing to take the time) you might get an interesting answer.

                The real question is, while it looks like 100%, can other programs take away the processing power they need at will? In other words, if another program needs 25% processing power, is the Civ3 coding going to limit that?
                Fitz. (n.) Old English
                1. Child born out of wedlock.
                2. Bastard.

                Comment


                • #9
                  This is something you can do in XP, so maybe you can do it in 2K.

                  In the control panel, go to system, then the advanced tab, then the button for performance. Go to it's advanced tab, and you can select whether programs or background services get priority. Another and probably better way is to Ctrl+Alt+Del, go to services, and right click on a service. You can then set a priority level to a service, and see if Civ3 still goes at 100%.
                  Rhett Monroe Chassereau

                  "I use to be with it, then they changed what it is. And what I'm with isn't it, and what is it seems strange and scary to me." -Abe Simpson

                  Comment


                  • #10
                    On an earlier thread memory usage of 700+ was seen - mostly due to the path-finding algorithm. This is why large maps are so slow and why it is not recommended to have other programs running.
                    "An Outside Context Problem was the sort of thing most civilisations encountered just once, and which they tended to encounter rather in the same way a sentence encountered a full stop" - Excession

                    Comment


                    • #11
                      Originally posted by bongo
                      Most programmers learn the difference between constant polling and events within the first couple of minths at school.
                      Even assuming that that's true today, programmers with 10 years of professional experience or more "grew up" as programmers in a different era. Back when I was in college (mid-to-late 80's), practically everything we did was text-based, which made the concept of event-driven programming generally irrelevant. On almost all personal computers (Amiga being an exception, but how many colleges used those?), there was no such thing as multitasking, and thus no need to worry about wasting resources someone else's program might need. And on big multiuser systems, the system calls we used isolated us from the underlying event mechanisms that protected against wasting computing power. GUI programming was still relatively new, and certainly not something simple enough to include in a typical freshman course (if a college offered a course in it at all). So no, we definitely did not learn about polling versus event-driven programming in the first two weeks.

                      I certainly hope that today's college students are being indoctrinated in good, multitasking-friendly programming practices from the beginning. But that still leaves the problem of experienced developers who spent their early programming careers not having to worry about playing nicely with other programs and who haven't made the adjustment to today's multitasking systems yet.

                      Nathan

                      Comment


                      • #12
                        You'll find that a great many Windows games do this, and it isn't bad programming.

                        The game simply makes use of whatever CPU time isn't being used by other parts of the system.

                        You should have no problems multitasking with Civ3 in the background...

                        Comment


                        • #13
                          Originally posted by Fitz
                          The real question is, while it looks like 100%, can other programs take away the processing power they need at will? In other words, if another program needs 25% processing power, is the Civ3 coding going to limit that?
                          With Civ 3 wanting to use as much processing power as the operating system is willing to let it, the big question becomes how much power the OS is willing to give it when another program also wants processing power. Under Windows NT 4.0, if "foreground boost" was set to none, Civ 3 could expect a minimum of about half the CPU cycles, leaving whatever else you're running limited to the other half (assuming two programs competing for cycles). With a higher foreground boost (the default), the program you're actively using would get a higher percentage of the available processing power. I imagine the settings to optimize for foreground or background processing in Windows 2000 and XP serve a similar purpose.

                          I'd have to do some experimenting to find out the point at which Civ 3's desire for processing cycles would interfere significantly with another program with Civ 3 running in the background. But unless a program pushes the CPU fairly close to its limit, Civ 3's polling loop probably won't be a big deal as long as optimization favors the foreground program. (Of course competition for memory may be another matter).

                          Nathan

                          Comment


                          • #14
                            Originally posted by Frugal_Gourmet
                            You'll find that a great many Windows games do this, and it isn't bad programming.

                            The game simply makes use of whatever CPU time isn't being used by other parts of the system.

                            You should have no problems multitasking with Civ3 in the background...
                            Rather than keep speculating, I downloaded and built a copy of the Dhrystone benchmark and ran it to see how Civ 3 affects its performance. Dhrystone is a bit obsolete for most purposes these days, but it should be fine for this one.

                            Without Civ 3 running, Dhrystone took 36-38 seconds to complete 50 million iterations. With Civ 3 running, it took 51-53 seconds. So having Civ 3 running in the background saps in the neighborhood of 30% of a Win2K system's performance. The game isn't just sitting back using cycles no one else wants.

                            I did, however, figure out what it does with at least some of those cycles. There's some eye candy (related to cities celebrating, in the case of the game I loaded for the test) that the game keeps going whether anyone is watching or not. It would be nice if they turned that off when their program loses focus, but at least it's not quite as bad as doing absolutely nothing.

                            Nathan

                            Comment


                            • #15
                              I did, however, figure out what it does with at least some of those cycles. There's some eye candy (related to cities celebrating, in the case of the game I loaded for the test) that the game keeps going whether anyone is watching or not.
                              nbarclay hit it right on the head. I play on a powerbook g4 (yes a mac ) and for those who are unfamiliar with these laptops, they get hot when being used alot. like hot enough to burn your legs. and the internal fan has 3 audibly different settings. While actively playing civ3 the fan is ALWAYS on high and the bottom is ALWAYS too hot to touch. I arrived at the same conclusion that nbarclay did, that there is always SOMETHING going on that needs cycles. like your rifleman sneezing or WLTKD fireworks, but also, workers. remember that workers are ALWAYS in motion unless garrisoned in a city or fortified out in the open (which happens often, I know )

                              even though I'm not on windows but mac os X (which has some of the best multi-tasking available on a desktop) I though some of you might want to know that it is not just on the evil empire's machines that display this behavior but us underdogs have it too. which seems that it falls squarely in the Wasteful Programming arena.

                              lateralis
                              "As far as I'm concerned, humans have yet to come up with a belief worth believing." --George Carlin

                              Comment

                              Working...
                              X