Skip to content
  • Philip Withnall's avatar
    gtkbuilder: Eliminate array reallocations in get_parameters() · fb998ff5
    Philip Withnall authored
    
    
    `gtk_builder_get_parameters()` is a hot path, being called twice for
    each object in each UI file in an application. The majority of objects
    have ≤ 8 properties, which are each filtered into either `parameters` or
    `filtered_parameters`.
    
    Unfortunately, both of those arrays are created as empty `GArray`s, and
    adding 8 elements to an empty `GArray` hits the worst possible case of
    reallocating and `memcpy()`ing the array 3 times. As the array size is
    doubled with each reallocation, the cost is not particularly well
    amortised when the array size is small.
    
    From the `ObjectInfo`, we actually know how many properties there are in
    total, so just allocate the arrays at the right size to begin with.
    
    This saves 7% of the instruction cycles needed to start up
    gnome-software to the point where it’s showing its main window,
    according to callgrind. gnome-software is making around 5500 calls to
    `gtk_builder_get_parameters()`.
    
    Signed-off-by: default avatarPhilip Withnall <withnall@endlessm.com>
    fb998ff5