Re: [RFC PATCH v4 3/7] libbpf: Optimize type lookup with binary search for sorted BTF
From: Eduard Zingerman
Date: Tue Nov 04 2025 - 19:19:21 EST
On Tue, 2025-11-04 at 16:11 -0800, Andrii Nakryiko wrote:
[...]
> > @@ -897,44 +903,134 @@ int btf__resolve_type(const struct btf *btf, __u32 type_id)
> > return type_id;
> > }
> >
> > -__s32 btf__find_by_name(const struct btf *btf, const char *type_name)
> > +/*
> > + * Find BTF types with matching names within the [left, right] index range.
> > + * On success, updates *left and *right to the boundaries of the matching range
> > + * and returns the leftmost matching index.
> > + */
> > +static __s32 btf_find_type_by_name_bsearch(const struct btf *btf, const char *name,
> > + __s32 *left, __s32 *right)
>
> I thought we discussed this, why do you need "right"? Two binary
> searches where one would do just fine.
I think the idea is that there would be less strcmp's if there is a
long sequence of items with identical names.