GC uBench

From MozillaWiki
Jump to: navigation, search

GC uBench

GC uBench ("garbage collector microbenchmark") is a tool for visualizing and measuring some aspects of GC behavior. It is located at <gecko>/js/src/devtools/gc-ubench/index.html and can be visited with the Firefox browser.

At the current time, you must use Firefox, as it uses a number of ES6 features not yet implemented in other engines.

Basic Visualization Usage

Latency Graph

The simplest way to use GC uBench is to stare fixatedly at the graph on the top of the page. It attempts to update at 60fps, and plots the delay between frames. Perfect behavior would be a flat line at 60fps (16 2/3 ms). A small amount of jitter around 60fps is fine too. If some frames end up getting skipped (as in, the requestAnimationFrame callback is not invoked at all for a while), you will see a horizontal line at a height corresponding to the delay after the callback finally gets invoked again.

If the correct preference is set (see "Heap Size Graph", below), this graph will also show a vertical line whenever there is a GC. Minor GCs are represented as short green lines at the top of the graph; major GC slices are orange and cover the whole graph. You will commonly see no GCs for a while, then a flurry of major GC slices, and then a gap until the GC kicks in again. All major GC slices will be accompanied by a minor GC (the nursery is cleared at the beginning of a GC slice.)

Heap Size Graph

Additionally, you can click the checkbox to display heap sizes. This requires a preference to be set; the page will instruct you as to which one. The size graph tracks various metrics related to the size of the GC heap and malloced memory. The graph also displays various thresholds used when deciding when/whether to GC. At the moment, these don't seem to correspond very well with actual behavior, so their accuracy should be regarded with suspicion.

Load

You can open up additional tabs in the background to see their effects on the GC behavior. The GC uBench graph *must* be in the foreground and visible in order to collect data, as it relies entirely upon requestAnimationFrame.

You can also apply artificial load by selecting from the dropdown. Initially, it will be set to noAllocations. Any other setting will create some number of objects for every frame seen. (Note that this means that a long GC pause will allocate no objects during the pause; it does not allocate more after the pause ends in order to catch up.) These objects are placed into one of a fixed number of piles. The piles are filled in a round-robin manner, so that when all piles are filled in, the oldest pile will become garbage.

Each load type is preconfigured with garbage-per-frame and garbage-piles settings. These are chosen to produce "interesting" behavior, and are probably a decent start for an investigation. (Alternatively, it would be nice to plug in realistic values to ensure that the garbage collector can handle them.)

Running tests

GC uBench also provides a mechanism to run controlled tests. The "Run One Test" button will run for a fixed amount of time, measuring how much time is spent GCing per second of mutator execution. (The mutator is the main program; from the perspective of the GC, its only relevance is that it allocates GC things and modifies the graph of existing GC things.)

"Run All Tests" will do the same, but iterating through all loads. Note that each load will be run with its default settings. If you want nondefault settings, you'll need to run the tests one at a time.

Finally, the oddly named "Find Breaking Point" will attempt to search through the space of possible garbage-per-frame values to hit a specific target. Currently, it will try to find a setting that will hit 20fps 50% of the time. The resulting numbers are pretty unstable, but they should show large differences.