Patch 8.2.5028
Problem:    Syntax regexp matching can be slow.
Solution:   Adjust the counters for checking the timeout to check about once
            per msec. (closes #10487, closes #2712)
Files:      src/regexp_bt.c, src/regexp_nfa.c


*** ../vim-8.2.5027/src/regexp_bt.c     2022-05-18 15:03:58.171540249 +0100
--- src/regexp_bt.c     2022-05-27 15:19:01.410895862 +0100
***************
*** 3271,3278 ****
            break;
        }
  #ifdef FEAT_RELTIME
!       // Check for timeout once in a 100 times to avoid overhead.
!       if (tm != NULL && ++tm_count == 100)
        {
            tm_count = 0;
            if (profile_passed_limit(tm))
--- 3271,3280 ----
            break;
        }
  #ifdef FEAT_RELTIME
!       // Check for timeout once in 250 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 (tm != NULL && ++tm_count == 250)
        {
            tm_count = 0;
            if (profile_passed_limit(tm))
***************
*** 3313,3319 ****
        op = OP(scan);
        // Check for character class with NL added.
        if (!rex.reg_line_lbr && WITH_NL(op) && REG_MULTI
!                            && *rex.input == NUL && rex.lnum <= 
rex.reg_maxline)
        {
            reg_nextline();
        }
--- 3315,3321 ----
        op = OP(scan);
        // Check for character class with NL added.
        if (!rex.reg_line_lbr && WITH_NL(op) && REG_MULTI
!                          && *rex.input == NUL && rex.lnum <= rex.reg_maxline)
        {
            reg_nextline();
        }
***************
*** 4990,4997 ****
            else
                ++col;
  #ifdef FEAT_RELTIME
!           // Check for timeout once in a twenty times to avoid overhead.
!           if (tm != NULL && ++tm_count == 20)
            {
                tm_count = 0;
                if (profile_passed_limit(tm))
--- 4992,5001 ----
            else
                ++col;
  #ifdef FEAT_RELTIME
!           // Check for timeout once in 500 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 (tm != NULL && ++tm_count == 500)
            {
                tm_count = 0;
                if (profile_passed_limit(tm))
*** ../vim-8.2.5027/src/regexp_nfa.c    2022-05-18 15:03:58.171540249 +0100
--- src/regexp_nfa.c    2022-05-27 15:33:31.154972581 +0100
***************
*** 5649,5659 ****
      static int
  nfa_did_time_out()
  {
!     if (nfa_time_limit != NULL && profile_passed_limit(nfa_time_limit))
      {
!       if (nfa_timed_out != NULL)
!           *nfa_timed_out = TRUE;
!       return TRUE;
      }
      return FALSE;
  }
--- 5649,5675 ----
      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
!           // timeout it keeps timing out until the time limit is changed.
!           tm_count = 0;
!       }
!       else
!           ++tm_count;
      }
      return FALSE;
  }
*** ../vim-8.2.5027/src/version.c       2022-05-27 13:52:05.118724853 +0100
--- src/version.c       2022-05-27 15:15:04.154404055 +0100
***************
*** 736,737 ****
--- 736,739 ----
  {   /* Add new patch number below this line */
+ /**/
+     5028,
  /**/

-- 
I have to exercise early in the morning before my brain
figures out what I'm doing.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220527143601.5CEBC1C1929%40moolenaar.net.

Raspunde prin e-mail lui