patchGNU nano - Patches: patch #9713, regex hashing, caching, and GC

 
 

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

patch #9713: regex hashing, caching, and GC

Submitter:  easyaspi314 <easyaspi314>
Submitted:  Sat 03 Nov 2018 02:25:41 AM UTC
   
 
Priority:  3 - Low Status:  Wont Do
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Release:  None

Thu 15 Nov 2018 06:23:37 PM UTC, comment #1: 

As said on the mailing list: far too much code for a minor speedup (in the default setup).

Benno Schulenberg <bens>
Group administrator
Sat 03 Nov 2018 02:25:41 AM UTC, original submission:  

 - regex.c caches regexes in a hashmap to avoid regcomp/regfree hell, and allows us to easily reuse identical regexes.
 - By default, there are 64 entries, and an FNV-1a hash is used. Duplicates are handled by putting nregex_t in a two-way linked list.
 - It automatically replaces regexec with strstr if it detects a string with no special characters.
 - It implements semi-automatic garbage collection to remove unreferenced regexes.
   - All regex usage is refcounted, being incremented in nregcomp and decremented on nregfree. nregfree only marks it for GC, the real one is _nregfree. Probably not the best name, I know.
   - This cleans up a lot of the extra regex from unused syntaxes and stuff.
   - Manual GC is called when opening or closing buffers.
   - Otherwise, it will check every 512 times either nregexec, nregcomp, or nregfree is called and there are enough unused regexes to warrant it, but only when the edit window is not NULL, to reduce startup lag.
 - It improves the situation with, but does not fix, #54928.
 - It greatly improves startup performance, especially with a ton of rc files:

   macOS 10.13.6
   Gnulib regex engine
   Apple LLVM version 9.1.0 (clang-902.0.39.2) - Clang ~5.0
   MacBook (13-inch, Mid 2009) - MacBook5,2
   2.13 GHz Intel Core 2 Duo (P7450, Penryn)
   4 GB RAM


   ~/.nanorc:
        set tabsize 4
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        include "~/nano2/syntax/*.nanorc"
        set tabstospaces
        set nowrap
        set mouse
        bind M-Q tabstospaces all
        bind M-S flipreplace all
        bind m-s flipreplace all

   Without the patch:
       $ time ./nano winio.c
       ^X buffered
       real    0m1.550s
       user    0m1.329s
       sys     0m0.060s
       (no notable benefits from a hot cache)
   With the patch:
       (Cold)
       $ time ./nano winio.c
       ^X buffered
       real    0m0.441s
       user    0m0.125s
       sys     0m0.061s
       (Hot)
       $ time ./nano winio.c
       ^X buffered
       real    0m0.227s
       user    0m0.123s
       sys     0m0.062s


Anyways, I think this should be used as in addition to an actual fix for #54928. The dupe-removal will help for the case where, say, the user puts their own syntax definitions in their personal .nanorc even though the system ones are already included in /etc/nanorc. Many of the "extended syntax definitions" copy the existing ones, so if we can save on most of the duplicates, that is a bonus.

The garbage collection will also be helpful for searches, as we can easily reuse compiled regexes.

easyaspi314 <easyaspi314>

 

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

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by easyaspi314 (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-07-04 bens Open/ClosedOpen Closed
    2018-11-15 bens Priority5 - Normal 3 - Low
        StatusNone Wont Do
        Summarynregex_t: regex caching, hashing, and GC - partial workaround for #54928. regex hashing, caching, and GC
    2018-11-03 easyaspi314 Attached File- Added 0001-Implement-the-caching-regex.c-with-nregex_t.patch, #45351

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code