Skip to content

Commit 788a701

Browse files
committed
Fix #81424: PCRE2 10.35 JIT performance regression
We backport the respective upstream fix[1] to our bundled pcre2lib plus the follow-up fix[2] for a functional regression. [1] <PCRE2Project/pcre2@dc5f966> [2] <PCRE2Project/pcre2@e7af7ef> Closes GH-7573.
1 parent fcabe69 commit 788a701

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- MySQLi:
66
. Fixed bug #81494 (Stopped unbuffered query does not throw error). (Nikita)
77

8+
- PCRE:
9+
. Fixed bug #81424 (PCRE2 10.35 JIT performance regression). (cmb)
10+
811
- Streams:
912
. Fixed bug #54340 (Memory corruption with user_filter). (Nikita)
1013

ext/pcre/pcre2lib/pcre2_jit_compile.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,13 @@ SLJIT_ASSERT(*cc == OP_ONCE || *cc == OP_BRA || *cc == OP_CBRA);
12491249
SLJIT_ASSERT(*cc != OP_CBRA || common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] != 0);
12501250
SLJIT_ASSERT(start < EARLY_FAIL_ENHANCE_MAX);
12511251

1252+
next_alt = cc + GET(cc, 1);
1253+
if (*next_alt == OP_ALT)
1254+
fast_forward_allowed = FALSE;
1255+
12521256
do
12531257
{
12541258
count = start;
1255-
next_alt = cc + GET(cc, 1);
12561259
cc += 1 + LINK_SIZE + ((*cc == OP_CBRA) ? IMM2_SIZE : 0);
12571260

12581261
while (TRUE)
@@ -1521,7 +1524,7 @@ do
15211524
{
15221525
count++;
15231526

1524-
if (fast_forward_allowed && *next_alt == OP_KET)
1527+
if (fast_forward_allowed)
15251528
{
15261529
common->fast_forward_bc_ptr = accelerated_start;
15271530
common->private_data_ptrs[(accelerated_start + 1) - common->start] = ((*private_data_start) << 3) | type_skip;
@@ -1569,8 +1572,8 @@ do
15691572
else if (result < count)
15701573
result = count;
15711574

1572-
fast_forward_allowed = FALSE;
15731575
cc = next_alt;
1576+
next_alt = cc + GET(cc, 1);
15741577
}
15751578
while (*cc == OP_ALT);
15761579

@@ -11152,7 +11155,7 @@ early_fail_type = (early_fail_ptr & 0x7);
1115211155
early_fail_ptr >>= 3;
1115311156

1115411157
/* During recursion, these optimizations are disabled. */
11155-
if (common->early_fail_start_ptr == 0)
11158+
if (common->early_fail_start_ptr == 0 && common->fast_forward_bc_ptr == NULL)
1115611159
{
1115711160
early_fail_ptr = 0;
1115811161
early_fail_type = type_skip;

ext/pcre/tests/bug81424a.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #81424 (PCRE2 10.35 JIT performance regression)
3+
--DESCRIPTION--
4+
We're testing against the functional regression which has been introduced by
5+
fixing the performance regression.
6+
--FILE--
7+
<?php
8+
var_dump(
9+
preg_match('/(?P<size>\d+)m|M/', "4M", $m),
10+
$m
11+
);
12+
?>
13+
--EXPECT--
14+
int(1)
15+
array(1) {
16+
[0]=>
17+
string(1) "M"
18+
}

0 commit comments

Comments
 (0)