bugGNU nano - Bugs: bug #59945, the handling of multiline regexes...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #59945: the handling of multiline regexes is too slow

Submitter:  Benno Schulenberg <bens>
Submitted:  Tue 26 Jan 2021 10:52:09 AM UTC
   
 
Severity:  2 - Minor Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Wed 27 Jan 2021 04:21:21 PM UTC, comment #2: 

Fixed in git, commit 43d94692, by searching for an end match only for the first row of the screen.

With this change, typing the third single quote at the top of the buffer now takes around 37 ms (instead of around 1000 ms).  But... after jumping to the end of the buffer, and then paging around there now takes around 70 ms (instead of around 8 ms before).

Seventy milliseconds is too much, but... applying a Python syntax to the NEWS file is really a misuse, a pathological case.  Paging around near the tail of a real 2000-line Python file now takes around 20 ms per refresh, instead around 8 ms before the commit.  That is an acceptable time.

Benno Schulenberg <bens>
Group administrator
Tue 26 Jan 2021 06:37:53 PM UTC, comment #1: 

In current git, uncomment the #define TIMEREFRESH line in src/winio.c, recompile and then run:

src/nano --rcfile=syntax/python.nanorc -Ypython +1 NEWS

See that this first "refresh" takes less than 3 ms.  Page down and up a bit.  See that the refresh times vary considerably, but are mostly in the range of 5 to 10 ms.  Type M-/ to go to end-of-buffer, and page up and down a bit.  See that the refresh times are roughly in the same range.

Now type M-\ followed by three single quotes: '''.
See that the refresh time for the third quote is around a 1000 ms.  (All this, of course, on my partical, low-end laptop.)  Now type <PageDown> a few times.  See that the refresh times slowly decrease, by roughly 10 or 20 ms per step.  Now type M-/.  See that at end-of-buffer the refresh times are still around  5 to 10 ms.

Benno Schulenberg <bens>
Group administrator
Tue 26 Jan 2021 10:52:09 AM UTC, original submission:  

To reproduce, run:

src/nano --rcfile=syntax/python.nanorc -Ypython +1 NEWS

Now slowly type three single quotes: ' ' '.

Upon typing the third quote, the cursor will be off for about a second as nano is busy repainting the screen.  This takes such a long time because for each row nano frantically tries to find another triple quote that matches the one at the start of the buffer.  For each row of the sreen it runs through all two thousand lines of the file, trying to match it with the triple-quote 'end' regex.  This is silly.  After the first run through the buffer (for the first row), it should have marked all lines as CWOULDBE and for each subsequent row it should honor that mark and just ignore the corresponding 'end' regex (because there will not be a match, it has already been determined).

Now type <PageDown>.  It takes a second before the screen gets redrawn and shows the second page of the buffer.  Now type <PageUp>.  Again it takes a second for the screen to get redrawn.  Now type <PageUp> quickly three times.  The cursor is hidden for three seconds while nano is busy redrawing the screen three times.  This is absurd.  When at the top of the buffer, any backward-moving keystroke should not trigger a redraw.

Now do the same with a nano before version 2.7.5.  (You will have  to move your .nanorc out of the way and copy syntax/python.nanorc into its place, and add quotes around the syntax name: "python".) Typing the third single quote and pressing <PageDown> are just as slow.  But pressing <PageUp> is instantaneous.  Apparently, while fixing the miscoloring bugs, I have undone some of the speedup that the multiline cache was supposed to provide.

Expected behavior: nano should try only once to find a matching 'end' when an edit changes the multiline-matching status of the current line (or when multiple lines are pasted or inserted).

Benno Schulenberg <bens>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-25 bens Open/ClosedOpen Closed
    2021-01-27 bens Severity3 - Normal 2 - Minor
        StatusNone Fixed
    2021-01-26 bens Assigned toNone bens

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code