To: vim_dev@googlegroups.com Subject: Patch 8.2.5028 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ 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 -- Bram@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 ///