ankurdave / color-identifiers-mode

Emacs minor mode to highlight each source code identifier uniquely based on its name
312 stars 23 forks source link

Slow parsing of huge (26k+ lines) python files #103

Open Hi-Angel opened 1 year ago

Hi-Angel commented 1 year ago

Steps to reproduce

  1. Get a python file wget https://raw.githubusercontent.com/qutebrowser/qutebrowser/master/qutebrowser/browser/browsertab.py
  2. Make a 1.py file that is twenty times larger: for i in $(seq 1 20); do cat browsertab.py >> 1.py; done
  3. Open the 1.py file
  4. Evaluate (benchmark-run 1 (color-identifiers:list-identifiers))

Expected

0.2 or 0.3 seconds

Actual

1.4 seconds

Additional information

benchmark-report says that 70% of time is spent in internal Emacs function we call (sexp-at-point).

So one solution to this problem could be optimizing this function.

Another good idea might be to modify upstream python-mode so that they mark args inside defuns with a font-lock-variable-name-face face, which would allow to get rid of color-identifiers:python-get-declarations in preference of the generic color-identifiers:get-declarations (well, maybe not completely, but at least for Emacs versions that will support that feature)

Hi-Angel commented 1 year ago

I added a commit that interrupts parsing if a user becomes active, so from a user POV that problem doesn't really exists anymore. At this point it is more of a developer interest, e.g. for refactoring etc.

Hi-Angel commented 1 year ago

upd: changed the title to match up the timings in "steps-to-reproduce".