Re: [PATCH v1] perf symbol: Remove symbol_name_rb_node

From: Namhyung Kim
Date: Tue Jun 20 2023 - 20:14:51 EST


On Tue, Jun 20, 2023 at 3:55 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Tue, Jun 20, 2023 at 2:01 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > Hi Ian,
> >
> > On Thu, Jun 15, 2023 at 1:08 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.
> >
> > Nice, I like the savings and lazy allocation.
> >
> > >
> > > 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.
> >
> > But I'm not sure if we need the index for the normal use cases.
> > IIUC only one place to require it: map__for_each_symbol_by_name.
> > Maybe we can have a separate API for it?
> >
> > In general, I'd like to split the commit to have on-demand part and
> > array changes separately.
>
> Thanks Namhyung! The current code is on-demand but the space for the
> rbnode must be reserved in the symbol_name_rb_node. We could on-demand
> resize symbols, but I don't think it makes sense.

Ok, but I think we can split the symbol_conf changes at least.

>
> If the worry is the patch set size, maybe as you suggest, we keep
> find_symbol_by_name to not take the optional index output parameter
> and introduce a find_symbol_by_name_idx function that takes a required
> index parameter. If that's good I'll send a v2.

Right, the patch size is a concern. But IIUC the find-by-name API
has two different use cases. So better splitting them for clarity.

Thanks,
Namhyung