[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d36a45b689e84ae7b9c1079221e054da@AcuMS.aculab.com>
Date: Sat, 28 Jan 2023 22:35:19 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Andy Shevchenko' <andy.shevchenko@...il.com>
CC: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Kees Cook <keescook@...omium.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Andy Shevchenko <andy@...nel.org>,
"Rasmus Villemoes" <linux@...musvillemoes.dk>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: RE: [PATCH v1 1/1] lib/string: Use strchr() in strpbrk()
From: Andy Shevchenko
> Sent: 28 January 2023 19:55
>
> On Sat, Jan 28, 2023 at 4:51 PM David Laight <David.Laight@...lab.com> wrote:
> >
> > From: Andy Shevchenko
> > > Sent: 27 January 2023 15:52
> > >
> > > Use strchr() instead of open coding it as it's done elsewhere in
> > > the same file. Either we will have similar to what it was or possibly
> > > better performance in case architecture implements its own strchr().
> >
> > Except that you get a whole load of calls to strchr() for (typically)
> > very few characters.
> > So the cost of the calls dominates, anything that tries to speed up
> > strchr() for long strings will also slow things down.
>
> Hmm... I haven't seen the calls, I assume gcc simply inlined a copy of that.
Anything gcc itself inlines is likely to be optimised for long strings
(where inlining probably makes less difference).
In any case that will bloat the function - and you saw a size reduction.
About the worst thing that can happen here is that gcc realises the open
coded loop is strchr() and then inlines its own 'fast' copy.
Which is the last thing you want if the string is only a few characters
long.
>
> ...
>
> > Although I very much doubt strpbrk() is used anywhere where
> > performance matters.
>
> strsep()/strspn() are the users.
I bet they aren't called anywhere that matters.
There is also a significant different.
strsep() is probably looking for a very small number of characters.
strspn() could easily have all alphabetics.
For long strings you can actually use a bitmap of the characters.
On 64bit this can, with care, be held in 4 registers.
32bit is more problematic.
But is you are just looking for " \t" the overheads are massive.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists