Re: [PATCH] driver core: auxiliary bus: Optimize auxiliary_match_id()
From: Greg Kroah-Hartman
Date: Tue Sep 02 2025 - 08:53:32 EST
On Tue, Sep 02, 2025 at 08:42:24PM +0800, Zijun Hu wrote:
> On 2025/9/2 20:20, Greg Kroah-Hartman wrote:
> > On Tue, Sep 02, 2025 at 08:05:32PM +0800, Zijun Hu wrote:
> >> From: Zijun Hu <zijun.hu@xxxxxxxxxxxxxxxx>
> >>
> >> Variable @match_size is fixed in auxiliary_match_id().
> >>
> >> Optimize the function by moving the logic calculating the variable
> >> out of the for loop.
> > Optimize it how? Does this actually result in a difference somehow, if
> > so, what?
> >
>
> auxiliary_match_id() repeatedly calculates variable @match_size in the
> for loop. however, the variable is fixed actually. so it is enough to
> calculate the variable once.
>
> Optimize it by moving the logic calculating the variable out of the for
> loop, and it result in:
>
> 1) calculate the variable once instead of repeatedly.
> 2) it will return as early as possible if device name is unexpected,
> namely, (@p == NULL).
>
> so this fix will improve performance.
This isn't a "performant" path at all, is it?
I'm not disagreeing that calculating this all the time is a bad idea,
but please be reasonable. If it can't be measured, you can't really say
it will "improve performance" :)
thanks,
greg k-h