Patch 8.2.5036

5 views
Skip to first unread message

Bram Moolenaar

unread,
May 28, 2022, 6:12:25 AM5/28/22
to vim...@googlegroups.com

Patch 8.2.5036 (after 8.2.5028)
Problem: Using two counters for timeout check in NFA engine.
Solution: Use only one counter. Tune the counts based on guessing.
Files: src/regexp_nfa.c


*** ../vim-8.2.5035/src/regexp_nfa.c 2022-05-27 15:35:23.850892910 +0100
--- src/regexp_nfa.c 2022-05-28 11:03:04.205606132 +0100
***************
*** 4053,4059 ****
#ifdef FEAT_RELTIME
static proftime_T *nfa_time_limit;
static int *nfa_timed_out;
- static int nfa_time_count;
#endif

static void copy_sub(regsub_T *to, regsub_T *from);
--- 4053,4058 ----
***************
*** 5646,5667 ****
}

#ifdef FEAT_RELTIME
static int
! nfa_did_time_out()
{
static int tm_count = 0;

! // Check for timeout once in 800 times to avoid excessive overhead from
! // reading the clock. The value has been picked to check about once per
! // msec on a modern CPU.
if (nfa_time_limit != NULL)
{
! if (tm_count == 800)
{
if (profile_passed_limit(nfa_time_limit))
{
if (nfa_timed_out != NULL)
*nfa_timed_out = TRUE;
return TRUE;
}
// Only reset the count when not timed out, so that when it did
--- 5645,5670 ----
}

#ifdef FEAT_RELTIME
+ /*
+ * Check if we are past the time limit, if there is one.
+ * To reduce overhead, only check one in "count" times.
+ */
static int
! nfa_did_time_out(int count)
{
static int tm_count = 0;

! // Check for timeout once in "count" times to avoid excessive overhead from
! // reading the clock.
if (nfa_time_limit != NULL)
{
! if (tm_count >= count)
{
if (profile_passed_limit(nfa_time_limit))
{
if (nfa_timed_out != NULL)
*nfa_timed_out = TRUE;
+ tm_count = 99999;
return TRUE;
}
// Only reset the count when not timed out, so that when it did
***************
*** 5722,5728 ****
if (got_int)
return FALSE;
#ifdef FEAT_RELTIME
! if (nfa_did_time_out())
return FALSE;
#endif

--- 5725,5732 ----
if (got_int)
return FALSE;
#ifdef FEAT_RELTIME
! // Check relatively often here, since this is the toplevel matching.
! if (nfa_did_time_out(100))
return FALSE;
#endif

***************
*** 5876,5887 ****
if (got_int)
break;
#ifdef FEAT_RELTIME
! if (nfa_time_limit != NULL && ++nfa_time_count == 20)
! {
! nfa_time_count = 0;
! if (nfa_did_time_out())
! break;
! }
#endif
t = &thislist->t[listidx];

--- 5880,5888 ----
if (got_int)
break;
#ifdef FEAT_RELTIME
! // do not check very often here, since this is a loop in a loop
! if (nfa_did_time_out(2000))
! break;
#endif
t = &thislist->t[listidx];

***************
*** 7126,7138 ****
if (got_int)
break;
#ifdef FEAT_RELTIME
! // Check for timeout once in a twenty times to avoid overhead.
! if (nfa_time_limit != NULL && ++nfa_time_count == 20)
! {
! nfa_time_count = 0;
! if (nfa_did_time_out())
! break;
! }
#endif
}

--- 7127,7135 ----
if (got_int)
break;
#ifdef FEAT_RELTIME
! // check regularly but not too often here
! if (nfa_did_time_out(800))
! break;
#endif
}

***************
*** 7178,7184 ****
#ifdef FEAT_RELTIME
nfa_time_limit = tm;
nfa_timed_out = timed_out;
- nfa_time_count = 0;
#endif

#ifdef ENABLE_LOG
--- 7175,7180 ----
*** ../vim-8.2.5035/src/version.c 2022-05-28 10:49:39.946234986 +0100
--- src/version.c 2022-05-28 11:06:13.865449080 +0100
***************
*** 736,737 ****
--- 736,739 ----
{ /* Add new patch number below this line */
+ /**/
+ 5036,
/**/

--
FATHER: Did you kill all those guards?
LAUNCELOT: Yes ... I'm very sorry ...
FATHER: They cost fifty pounds each!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages