git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: improve performance of PCRE2 bug 2642 bug workaround

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Mar 23, 2022, 01:09 UTC
Message-ID
<20220323010931.jzf7op7hdusdty33@carlos-mbp.lan>
In-Reply-To
<99b0adb6-26ba-293c-3a8f-679f59e7cb4d@web.de>
On Tue, Mar 22, 2022 at 09:26:10PM +0100, René Scharfe wrote:
Show 10 quoted lines
> Am 22.03.22 um 17:38 schrieb Paul Eggert:
> > Today, Carlo Arenas pointed out[1] that GNU grep didn't work around
> > PCRE2 bug 2642, which Git grep has a workaround for. While installing
> > a GNU grep patch to fix this[2] I noticed that Git's workaround
> > appears to be too pessimistic: on older PCRE2 libraries Git grep sets
> > PCRE2_NO_START_OPTIMIZE even when PCRE2_CASELESS is not set.
> 
> Interesting.  So you say bug 2642 [3] requires the flag PCRE2_CASELESS
> (i.e. --ignore-case) to be triggered.  (That's probably documented in
> Bugzilla, but I'm not authorized to access it.)
AFAIK the contents of the bugzilla are no longer accessible to anyone (lost in the migration of PCRE2 to github), but the use of PCRE2_CASELESS introduced in 95ca1f987e (grep/pcre2: better support invalid UTF-8 haystacks, 2021-01-24) might had been a mistake all along.
the bug will trigger when both PCRE2_UTF and PCRE2_MULTILINE are set (as shown in the PCRE2 regression added), with the later set by default in git and NEVER set in GNU grep, hence why I later retracted[6] my suggestion to add the workaround to grep, and suggest updating git with the following
Carlo
[6] https://lists.gnu.org/r/grep-devel/2022-03/msg00006.html
--- >8 ---
Subject: [PATCH] grep: remove check for case sensitivity in workaround for
 PCRE's bug2642

95ca1f987e (grep/pcre2: better support invalid UTF-8 haystacks, 2021-01-24) add a workaround to an old PCRE2 bug, but includes in the logic a partial check for case sensitivity without explanation.

Remove it so that the workaround (and its performance impact) will be only triggered when needed (both PCRE2_MULTILINE and PCRE2_UTF and JIT is used)

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 grep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/grep.c b/grep.c
index 82eb7da102..d910836569 100644
--- a/grep.c
+++ b/grep.c
@@ -296,8 +296,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
 		options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
 
 #ifndef GIT_PCRE2_VERSION_10_36_OR_HIGHER
-	/* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */
-	if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS))
+	/* Work around PCRE2 bug2642 fixed in 10.36 */
+	if (SUPPORT_JIT && PCRE2_MATCH_INVALID_UTF && (options & PCRE2_UTF))
 		options |= PCRE2_NO_START_OPTIMIZE;
 #endif
 
-- 
2.35.1.505.g27486cd1b2d
Previous: Paul EggertNext: Paul Eggert
Message 4 of 7 in “improve performance of PCRE2 bug 2642 bug workaround”
  1. Paul EggertMar 22, 2022
  2. René ScharfeMar 22, 2022
  3. Paul EggertMar 22, 2022
  4. Carlo Marcelo Arenas BelónMar 23, 2022
  5. Paul EggertMar 23, 2022
  6. René ScharfeMar 23, 2022
  7. Carlo ArenasMar 23, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.