Re: [PATCH v3] Improve performance of strstr

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Oct 18 17:29, Wilco Dijkstra wrote:
> v3: Add support for read ahead using strnlen, giving an additional 25% speedup
> on large inputs (both short and long needles).
> 
> This patch significantly improves performance of strstr by using Sunday's
> Quick-Search algorithm.  Due to its simplicity it has the best average
> performance of string matching algorithms on almost all inputs.  It uses a
> bad-character shift table to skip past mismatches.
> 
> The needle length is limited to 254 - this reduces the shift table memory 
> 4 to 8 times, lowering preprocessing overhead and minimizing cache effects.
> The limit also implies its worst-case performance is linear.
> 
> Larger needles are processed by the Two-Way algorithm.  The macro AVAILABLE
> has been improved to use strnlen to read the input in chunks.  This results
> in a 2.5 times speedup for large needles, reducing the performance drop when
> the Quick-Search algorithm can't be used.
> 
> The code for 1-4 byte needles has been simplified and now uses unsigned
> char.  Since the optimized code relies on 8-bit chars, we defer to the
> size-optimized implementation if CHAR_BIT > 8.
> 
> The performance gain of finding a set of randomly chosen words of size 8 in 
> 256 bytes of English text is 14 times on AArch64. For longer haystacks the
> gain is well over 20 times.
> 
> The size-optimized strstr has also been rewritten from scratch to improve
> performance.  On the same test the performance gain is 69%.
> 
> Tested against GLIBC testsuite, randomized tests and the GNULIB strstr test
> (https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-strstr.c).
> 
> --

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlvIyG8ACgkQ9TYGna5E
T6C+jg//eo7TiV6JBHB7w62zdNns9+rAsAf5mtQ7z2JTXoa7XpjuG+GkIeC5r4fw
YgESlBwtQjNfJZEOrktvXA/vOQJGaq+v4oj/gmtUuYQQs/TilcCgRRQGdKAWFwd4
clG/BLA5IkErDseG/3WrXCP2f1z5p8IGncsfx9yPTmZBUjf1AWdasnhHrN3sqxT7
a3uTFd7C+Ym52eDa/u+za8BQ7K2sea+6MeOH68c1W+QzEv8XOHtEqjiE9IJYYU1p
rvhJ+dHvcmT1N2MkhQThEZFyVJu5N81xduCLY7vIdtjGZEnPOTKyU2q6NMNSroT5
lFB+PSZFZqFeuamTqFzKV6rpEOQdYuKPdKXai10G8jX1AyD3FrP2gfV9ApnIyYx9
8nuxcs9sb3Kg7N2gIkBM+7pgzGUFOPYiBkYWrACEi3ZWXTNobo4X0r7gI/l70AaY
jxo3Es60xjiDFAUjp4cBH4cjpNaYs7Yud07+vTj0QoWBvq1hGB9thMrtxLRs7Fkk
OqqYI9xN5cvLaRElLHettiErMQYwOVcMdxyasUDHztoeacPhaq5sGvbAt26VNZAV
WXFeFuJAzJx4FNYnczGkyqYM9QCYMZLKq/4NFL/3tdV2DmjnX0XsNc8QyfNiuGa1
2KSt4XbqPUq1T2ZrIvkGCKtxrMOXEtaxKRyVJx74mPUQ64SC9rI=
=kz8K
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.