Skip to content

Commit 685668f

Browse files
avargitster
authored andcommitted
grep: stop using a custom JIT stack with PCRE v1
Simplify the PCRE v1 code for the same reasons as for the PCRE v2 code in the last commit. Unlike with v2 we actually used the custom stack in v1, but let's use PCRE's built-in 32 KB one instead, since experience with v2 shows that's enough. Most distros are already using v2 as a default, and the underlying sljit code is the same. Unfortunately we can't just pass a NULL to pcre_jit_exec() as with pcre2_jit_match(). Unlike the v2 function it doesn't support that. Instead we need to use the fatter pcre_exec() if we'd like the same behavior. This will make things slightly slower than on the fast-path function, but it's OK since we care less about v1 performance these days since we have and recommend v2. Running a similar performance test as what I ran in fbaceaa ("grep: add support for the PCRE v1 JIT API", 2017-05-25) via: GIT_PERF_REPEAT_COUNT=30 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_MAKE_OPTS='-j8 USE_LIBPCRE1=Y CFLAGS=-O3 LIBPCREDIR=/home/avar/g/pcre/inst' ./run HEAD~ HEAD p7820-grep-engines.sh Gives us this, just the /perl/ results: Test HEAD~ HEAD --------------------------------------------------------------------------------------- 7820.3: perl grep 'how.to' 0.19(0.67+0.52) 0.19(0.65+0.52) +0.0% 7820.7: perl grep '^how to' 0.19(0.78+0.44) 0.19(0.72+0.49) +0.0% 7820.11: perl grep '[how] to' 0.39(2.13+0.43) 0.40(2.10+0.46) +2.6% 7820.15: perl grep '(e.t[^ ]*|v.ry) rare' 0.44(2.55+0.37) 0.45(2.47+0.41) +2.3% 7820.19: perl grep 'm(ú|u)lt.b(æ|y)te' 0.23(1.06+0.42) 0.22(1.03+0.43) -4.3% It will also implicitly re-enable UTF-8 validation for PCRE v1. As noted in [1] we now have cases as a result where PCRE v1 is more eager to error out. Subsequent patches will fix that for v2, and I think it's fair to tell v1 users "just upgrade" and not worry about that edge case for v1. 1. https://public-inbox.org/git/CAPUEsphZJ_Uv9o1-yDpjNLA_q-f7gWXz9g1gCY2pYAYN8ri40g@mail.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3448923 commit 685668f

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

grep.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,6 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
394394

395395
#ifdef GIT_PCRE1_USE_JIT
396396
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
397-
if (p->pcre1_jit_on) {
398-
p->pcre1_jit_stack = pcre_jit_stack_alloc(1, 1024 * 1024);
399-
if (!p->pcre1_jit_stack)
400-
die("Couldn't allocate PCRE JIT stack");
401-
pcre_assign_jit_stack(p->pcre1_extra_info, NULL, p->pcre1_jit_stack);
402-
}
403397
#endif
404398
}
405399

@@ -411,18 +405,9 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
411405
if (eflags & REG_NOTBOL)
412406
flags |= PCRE_NOTBOL;
413407

414-
#ifdef GIT_PCRE1_USE_JIT
415-
if (p->pcre1_jit_on) {
416-
ret = pcre_jit_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
417-
eol - line, 0, flags, ovector,
418-
ARRAY_SIZE(ovector), p->pcre1_jit_stack);
419-
} else
420-
#endif
421-
{
422-
ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
423-
eol - line, 0, flags, ovector,
424-
ARRAY_SIZE(ovector));
425-
}
408+
ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
409+
eol - line, 0, flags, ovector,
410+
ARRAY_SIZE(ovector));
426411

427412
if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
428413
die("pcre_exec failed with error code %d", ret);
@@ -439,14 +424,11 @@ static void free_pcre1_regexp(struct grep_pat *p)
439424
{
440425
pcre_free(p->pcre1_regexp);
441426
#ifdef GIT_PCRE1_USE_JIT
442-
if (p->pcre1_jit_on) {
427+
if (p->pcre1_jit_on)
443428
pcre_free_study(p->pcre1_extra_info);
444-
pcre_jit_stack_free(p->pcre1_jit_stack);
445-
} else
429+
else
446430
#endif
447-
{
448431
pcre_free(p->pcre1_extra_info);
449-
}
450432
pcre_free((void *)p->pcre1_tables);
451433
}
452434
#else /* !USE_LIBPCRE1 */

grep.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
1515
#define GIT_PCRE_STUDY_JIT_COMPILE 0
1616
#endif
17-
#if PCRE_MAJOR <= 8 && PCRE_MINOR < 20
18-
typedef int pcre_jit_stack;
19-
#endif
2017
#else
2118
typedef int pcre;
2219
typedef int pcre_extra;
23-
typedef int pcre_jit_stack;
2420
#endif
2521
#ifdef USE_LIBPCRE2
2622
#define PCRE2_CODE_UNIT_WIDTH 8
@@ -85,7 +81,6 @@ struct grep_pat {
8581
regex_t regexp;
8682
pcre *pcre1_regexp;
8783
pcre_extra *pcre1_extra_info;
88-
pcre_jit_stack *pcre1_jit_stack;
8984
const unsigned char *pcre1_tables;
9085
int pcre1_jit_on;
9186
pcre2_code *pcre2_pattern;

0 commit comments

Comments
 (0)