Re: [PATCH bpf-next v9 04/10] libbpf: Optimize type lookup with binary search for sorted BTF
From: Eduard Zingerman
Date: Tue Dec 16 2025 - 21:57:24 EST
On Wed, 2025-12-17 at 10:32 +0800, Donglin Peng wrote:
[...]
> > > + if (unlikely(kind == -1))
> > > + return idx;
> > > +
> > > + t = btf_type_by_id(btf, idx);
> > > + if (likely(BTF_INFO_KIND(t->info) == kind))
> > > + return idx;
> > > +
> > > + for (idx++; idx <= end_id; idx++) {
> > > + t = btf__type_by_id(btf, idx);
> > > + tname = btf__str_by_offset(btf, t->name_off);
> > > + if (strcmp(tname, type_name) != 0)
> > > + return libbpf_err(-ENOENT);
> > > + if (btf_kind(t) == kind)
> > ^^^^^^^^^^^^^^^^^^^
> > Is kind != -1 check missing here?
>
> The check for kind != -1 is unnecessary here because it has already been
> performed earlier in the logic, after btf_find_by_name_bsearch successfully
> returned a valid idx. In v8, the implementation of btf_find_by_name_bsearch
> was refined for better performance, and when idx > 0, it guarantees that the
> name has been matched.
>
> Thank you for the review.
> Donglin
Ack, missed that, thank you for explaining.