Re: [PATCH v2 1/2] perf symbol: Remove symbol_name_rb_node

From: Namhyung Kim
Date: Wed Jun 21 2023 - 23:51:18 EST


Hi Ian,

On Tue, Jun 20, 2023 at 11:37 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> Most perf commands want to sort symbols by name and this is done via
> an invasive rbtree that on 64-bit systems costs 24 bytes. Sorting the
> symbols in a DSO by name is optional and not done by default, however,
> if sorting is requested the 24 bytes is allocated for every
> symbol.
>
> This change removes the rbtree and uses a sorted array of symbol
> pointers instead (costing 8 bytes per symbol). As the array is created
> on demand then there are further memory savings. The complexity of
> sorting the array and using the rbtree are the same.
>
> To support going to the next symbol, the index of the current symbol
> needs to be passed around as a pair with the current symbol. This
> requires some API changes.
>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
>
> v2. map__find_symbol_by_name_idx so that map__find_symbol_by_name
> doesn't need an optional parameter. Separate out
> symbol_conf.sort_by_name removal.
> ---

[SNIP]
> void dso__sort_by_name(struct dso *dso)
> {
> - dso__set_sorted_by_name(dso);
> - return symbols__sort_by_name(&dso->symbol_names, &dso->symbols);
> + mutex_lock(&dso->lock);
> + if (!dso__sorted_by_name(dso)) {
> + size_t len;
> +
> + dso->symbol_names = symbols__sort_by_name(&dso->symbols, &len);
> + if (dso->symbol_names) {
> + dso->symbol_names_len = len;
> + dso__set_sorted_by_name(dso);
> + }
> + }
> + mutex_unlock(&dso->lock);

I think this part deserves a separate commit.

Thanks,
Namhyung