Search code examples
phpintellij-ideaidephpstorm

Jetbrains PHPStorm TODO slows down editing


so whenever I have the TODO display open, the editing of files become noticeable slower in Jetbrains PHPStorm

If I switch the TODO display to something else, the editing becomes fast again

This is due to the fact that PHPStorm is scanning the edited file for whether or not new TODOs appear in the edited file

Is there a way to prevent PHPStorm from doing this scanning all the time so that I can have the TODO window open without having my editing speed slows down?


Solution

  • JetBrains TODO preforms a RegEx search of potentially large amounts of text, so if there is a time-consuming pattern in your TODOs, things can slow considerably, or even hang.

    The problem lies with any regular expression matches that may have been defined to identify TODO items. The Java standard regular expression library used by JetBrains IDEs to match these items uses an algorithm of exponential complexity to search for '*.a' and similar patterns.

    Theoretically, it is possible to match any regexp very fast (a linear algorithm exists), > but many developers of regexp libs simply don't bother implementing it.

    In general, if your TODOs are lowing things down, look to the RegEx in your TODO items and see if you can narrow the scope of matches in order to improve performance.


    BTW, the same problem exists for the Python re module:

    >>> from timeit import timeit
    >>> timeit("import re; list(re.finditer('.*a', 'foo' * 10000))", number=1)
    0.6927990913391113
    >>> timeit("import re; list(re.finditer('.*a', 'foo' * 50000))", number=1)
    17.076900005340576