This content is outdated and is kept for historical interest only. GSlice has been deleted from GLib in favour of normal malloc().

Profiling GSlice

GSlice is the slab allocator we use everywhere in GLib. The slice allocator is meant to be efficient when used in heavily threaded environments, with a performance envelope geared towards minimising the waste of memory.

Considering the advancements in the implementation of the system allocators over the years, we're now considering deprecating the API, or changing its implementation.

Methodology

We've used a small test harness to run a performance comparison of:

  • the system allocator
  • the g_malloc() wrappers provided by GLib

  • the g_slice_alloc() allocator

All of those have been compared against tcmalloc, a modern, efficient allocator optimised for multi-threaded environments, similar in goals to the GLib slice allocator.

Each test captures:

  • timing for each allocation
  • peak virtual memory usage

Additionally, it runs allocation tests using multiple threads to verify the scaling behaviour of the allocator.

In order to capture the behaviour of GSlice in its typical use case — many allocations of similar-sized small memory regions — on a typical desktop machine, the values for each tests are:

  • 64 kB of memory per allocation
  • 250000 allocations per run
  • 8 threads per run

The machine where the tests have been ran is an 8th gen Intel Core i7 CPU with 4 cores and 16GB of RAM.

The benchmark has been performed against the GNU libc version 2.27, as shipped by Fedora 28; tcmalloc is tcmalloc_minimal.so.4.5.1, as shipped by Fedora 28.

Results

g_slice_alloc / malloc / g_malloc / tcmalloc

A comparison of all the allocators

gslice-vs-gmalloc.png

malloc vs tcmalloc

A comparison between the system allocator and tcmalloc()

malloc.png

g_slice vs tcmalloc

A comparison between g_slice_alloc() using the GSlice implementation, and g_slice_alloc() using the system allocator replaced by tcmalloc()

gslice.png

g_object_new vs tcmalloc

A comparison between g_object_new() using the GSlice implementation, and g_object_new() using the system allocator replaced by tcmalloc()

gobject.png

g_slice_alloc vs g_object_new

A comparison between g_slice_alloc() and g_object_new()

gslice-vs-gobject.png

VM peak memory

A comparison of the peak memory usage for all allocators

total_memory.png

Alternative allocators

jemalloc

Homepage: http://jemalloc.net/

Comparison between changing the GSlice implementation among:

  • the magazine allocator (default)
  • jemalloc
  • tcmalloc via LD_PRELOAD

gslice-vs-gmalloc-jemalloc.png

total_memory-jemalloc.png

Projects/GLib/GSlicePeformanceTests (last edited 2023-07-29 12:32:23 by PhilipWithnall)