Giter Site home page Giter Site logo

Comments (3)

mbunkus avatar mbunkus commented on August 25, 2024

I've played around with this a bit more. Shortening the line to e.g. 370 characters gives me a result (= the buffer is fully populated and control returned to Emacs) within four or five seconds. Adding just a couple of words here makes the time-to-return-of-control shoot through the root.

With such a shortened line I've run the profiler on rg-the-function. The result is this:

- command-execute                                                7941  94%
 - call-interactively                                            7941  94%
  - apply                                                        7941  94%
   - call-interactively@ido-cr+-record-current-command               7941  94%
    - apply                                                      7941  94%
     - #<subr call-interactively>                                7941  94%
      - funcall-interactively                                    7771  92%
       - execute-extended-command                                7771  92%
        - sit-for                                                7766  92%
         - read-event                                            7218  86%
          - redisplay_internal (C function)                      7212  86%
           - jit-lock-function                                   7212  86%
            - jit-lock-fontify-now                               7212  86%
             - jit-lock--run-functions                           7212  86%
              - run-hook-wrapped                                 7212  86%
               - #<compiled 0xc19ad9>                            7212  86%
                - font-lock-fontify-region                       7212  86%
                 - font-lock-default-fontify-region               7212  86%
                    font-lock-fontify-keywords-region               7212  86%
         + redisplay                                              548   6%
        + command-execute                                           5   0%
      + byte-code                                                 170   2%
+ ...                                                             421   5%

This leads me to believe that the regular expressions you're using make the regex engine do costly backtracking causing exponential increase in time with increase in input (line) length.

Commenting out the very last entry of rg-mode-font-lock-keywords (("^\\(?:.+?-\\)*?[0-9]+-.*\n" (0 'rg-context-face))) makes display instantaneous.

The problem is that the first non-capturing parenthesis can be repeated any number of times (the * after the parenthesis), but its content can be an arbitrary number of characters long — a typical disaster for regex engines. Removing the * seems to work fine performance-wise:

("^\\(?:.+?-\\)?[0-9]+-.*\n" (0 'rg-context-face))

A quick test with rg-command-line-flags set to '("-C" "1") indicates the RE to work fine.

from rg.el.

dajva avatar dajva commented on August 25, 2024

Thanks for your thorough investigation. I agree with your conclusion.

from rg.el.

mbunkus avatar mbunkus commented on August 25, 2024

You're quite welcome! Thanks for providing such a useful mode in the first place.

from rg.el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.