World of Warcraft

60
View All Posts by This User Toggle Ignore / Unignore This User
  • 0. Memory, GC, World of Warcraft and You Part II   09/07/2007 11:20:21 AM PDT
quote reply
In the first installment of this series (http://forums.worldofwarcraft.com/thread.html?topicId=75469222), I presented an introduction to the incremental garbage collection system that was changed in the 2.0 codebase for World of Warcraft. Since this time there have been further observations, more testing, and better information with regards to the garbage collection system, so I wanted to provide an update.

How Does GC Work in World of Warcraft?

In Lua 5.0 (which was used in WoW prior to The Burning Crusade, the client used an atomic garbage collection system. What this meant was the system did nothing until you reached 200% of your starting memory usage, and then went through all objects in the system and collected those that weren't referenced anywhere.

In Lua 5.1, which is used in The Burning Crusade and beyond, an incremental garbage collection system was introduced. This garbage collection system has two steps:

* March through each object in the system and mark those that cannot be collected
* Collect any objects that have not been marked

In WoW, everytime a new object is allocated (strings, functions, tables, coroutines) the system takes a small slice of time, and runs through part of the garbage collection process. If the system is in the marking phase, then it will mark a few objects and then return to the rest of the system. When the mark phase is done, the system will deallocate a small slice of objects, each time new memory is allocated.

You can see how this works by doing the following:

1. Run the following script:

/script collectgarbage("collect"); collectgarbage("restart"); ChatFrame1:AddMessage(tostring(gcinfo())); for i=1,1e5 do local t = {} end; ChatFrame1:AddMessage(tostring(gcinfo()))

You should have two numbers printed to your chatframe, the first being your memory before creating a bunch of garbage and the second being your usage after creating the garbage. You should see a difference of around 2000 between these two numbers.

2. Run the same script, change "restart" in the second collectgarbage() call to "stop". You should see a difference of around 4000 between the two numbers.

3. Run /script collectgarbage("restart")

In the first example, the incremental garbage collector is running, so some of the new tables that are created are automatically deallocated by the system. In the second example, the garbage collector is off, so you can see that twice the memory is used by the system (since nothing is deallocated).

So is there a problem?
For most systems no. Any memory that is allocated will eventually be deallocated, but the overall system memory usage may appear to be a bit higher, since the garbage collector is a slower incremental process. If you have an extremely low amount of memory in your system, you could see some slowdown but it wouldn't be typical. There is one issue that can occur

What issue?

Consider the following description of the default garbage collection system:

* Memory is only deallocated when new memory is allocated.
* If the system has a large burst of garbage created by an addon, that garbage exists in the system
* Afterwards, in order for that to be collected, new allocations need to happen
* The default resting UI doesn't have a very large increasing rate of memory usage

As a result, it's very easy for a lot of garbage to be created that won't be collected for quite some period of time (with the default ui, as many tables as we created take longer than 5 minutes to collect). This doesn't cause an issue, but does show inflated numbers. The default garbage collector is doing exactly what it should do, but it can cause an addon to show a much higher memory usage number than intended.

How do we fix this non-problem?

Download the following addon that I have created: http://www.wowinterface.com/downloads/info7522-GCTweak.html

This addon is designed to run the garbage collection system periodically (over time) in addition to the way it responds to new memory allocations. These steps are only run when the player is not in combat, and only when their framerate is higher than the setting for the addon.

Once you're in game, run /gct <num> where <num> is a framerate you'd like the addon to be active when you're running faster than that. The addon should not negatively effect your framerate or system performance, but you can always turn the addon off if you find something different.

Net effect, you will have lower memory usage, and the garbage collector will be operating a bit closer to how it was intended. Feel free to ask any questions you have about the garbage collection system, (including very technical ones). This post is intentionally not very technical, and I know it can be very confusing :P

TLDR - Technical Version

Lua's incremental garbage collector only marks and deallocates in response to new allocatio

[ Post edited by Cladhaire ]


Display the information in an intelligent way.
Healing assignments
Decurse assignments
80
View All Posts by This User Toggle Ignore / Unignore This User
  • 1. Re: Memory, GC, World of Warcraft and You Par   09/07/2007 11:54:28 AM PDT
quote reply
Looks pretty nice clad. After looking through your code I would maybe recommend that you force a whole garbage collection cycle after certain events (e.g. Player enters city, dies, etc.).

Retired: Myrafae -- 70 Mage; Lolth -- 61 Priest
Author of Spellcraft: http://www.unm.edu/~batrick/spellcraft/
60
View All Posts by This User Toggle Ignore / Unignore This User
  • 2. Re: Memory, GC, World of Warcraft and You Par   09/07/2007 12:21:57 PM PDT
quote reply
That would be excessive, and not really have much point given the incremental garbage collector. We don't need to micromanage things, the system works just fine-- it just needs a little help getting the job done when it gets down.

[ Post edited by Cladhaire ]


Display the information in an intelligent way.
Healing assignments
Decurse assignments
Blizzard Entertainment
View All Posts by This User ignore-inactive
Slouken
Blizzard Poster
  • 4. Re: Memory, GC, World of Warcraft and You Par   09/07/2007 04:06:24 PM PDT
quote reply
FYI, something along these lines is in for 2.3.
80
View All Posts by This User Toggle Ignore / Unignore This User
  • Tichondrius
  • 6. Re: Memory, GC, World of Warcraft and You Par   09/08/2007 10:52:45 AM PDT
quote reply
WTB Ace version....



<3 Cladhaire ;)

I like stuff.
80
View All Posts by This User Toggle Ignore / Unignore This User
  • 8. Re: Memory, GC, World of Warcraft and You Par   09/09/2007 02:58:44 AM PDT
quote reply

Q u o t e:


hi myrafae lolz


hi emceeeeeee.... I miss getting chain feared by u in bgs

Retired: Myrafae -- 70 Mage; Lolth -- 61 Priest
Author of Spellcraft: http://www.unm.edu/~batrick/spellcraft/
19
View All Posts by This User Toggle Ignore / Unignore This User
  • 9. Re: Memory, GC, World of Warcraft and You Par   09/09/2007 11:42:11 AM PDT
quote reply
Clad, you need to shorten it up a bit. The whole post isn't being displayed due to the character limit per post, :(.

aKa Sixen on Battle.net
The Chat Gem Lives!
Retired King of italics.
http://www.Sixen.org
80
View All Posts by This User Toggle Ignore / Unignore This User
  • 10. Re: Memory, GC, World of Warcraft and You Par   09/09/2007 01:48:29 PM PDT
quote reply

Q u o t e:
WTB Ace version....



<3 Cladhaire ;)


Christ please tell me you're joking.

Balance druids have potential, in the same way nuclear weapons have potential.
I've yet to see one used effectively and hope to god I never have to.
2
View All Posts by This User Toggle Ignore / Unignore This User
  • 11. Re: Memory, GC, World of Warcraft and You Par   09/09/2007 02:17:41 PM PDT
quote reply

Q u o t e:


Christ please tell me you're joking.


This will totally destroy the theme, but that is a running joke, yes.

Have you considered that the IEF is already in-game, but in the form of an "idiot tax" - that is, increased repair bills for people who don't train/use the spell?
-- Daiman@Blackhand
60
View All Posts by This User Toggle Ignore / Unignore This User
  • 12. Re: Memory, GC, World of Warcraft and You Par   09/10/2007 05:33:04 PM PDT
quote reply
Keep in mind, the more resident memory you have, the longer the mark and sweep process will take, slowing the entire cycle. If you test it, you'll see much quicker collection if you're normally around 15 MiB, as opposed to running 130 MiB, which I'm testing at the moment :P

Display the information in an intelligent way.
Healing assignments
Decurse assignments
Forum Nav : Jump To This Forum
Blizzard Entertainment