PyCharm 3.1 hangs forever during indexing and unusable

前端 未结 4 2284
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 01:25

After updating to 3.1, PyCharm hangs forever (on OSX 10.9.1, Python 2.7.5) during the \"indexing\" of packages.

For me this occurs while indexing scipy (0.1

4条回答
  •  一向
    一向 (楼主)
    2021-02-14 02:06

    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 PyCharm 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.

    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
    

    In general, if indexing is taking a long time, or hanging, look to the RegEx in your TODO items and see if you can narrow the scope of matches in order to improve performance.

提交回复
热议问题