PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.03k stars 754 forks source link

Speed up _is_eol_token #1257

Closed correctmost closed 2 months ago

correctmost commented 2 months ago

Continuation of #1256 because I force pushed and cannot reopen that PR. (Sorry for the noise.)

If this PR seems too risky because of assumptions about tokenization, feel free to pass!

Stats

Before

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1478156    0.885    0.000    1.197    0.000 pycodestyle.py:1831(_is_eol_token)
  1472360    0.364    0.000    0.364    0.000 {method 'lstrip' of 'str' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.472 ± 0.196 18.067 18.848 1.00

After

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1478156    0.511    0.000    0.511    0.000 pycodestyle.py:1831(_is_eol_token)
   225341    0.055    0.000    0.055    0.000 {method 'lstrip' of 'str' objects}
Command Mean [s] Min [s] Max [s] Relative
pycodestyle . 18.360 ± 0.186 18.159 18.781 1.00
correctmost commented 2 months ago

Versions tested locally (on Arch Linux with pyenv):