Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long line perf of compilation-shell-minor-mode #24

Conversation

t0yv0
Copy link

@t0yv0 t0yv0 commented Apr 4, 2021

To reproduce the issue of Emacs freezing on long lines, do the following:

M-x shell
M-x compilation-shell-minor-mode
$ python3 -c 'print("x"*1024*8)'

Depending on the machine configuration, make your lines longer. 1024*8 is enough to freeze my MacBook Pro 2019 visibly but I need more characters to slow down an XPS-13 running Ubuntu.

In the real world the issue comes up when I'm enjoying my compilation-shell-minor-mode buffer but accidentally cat or print some data with very long lines. Then Emacs freezes and I experience one of my very rare moments of unhappiness with the editor.

Using M-x profiler-start, profiler-stop, profiler-report the culprit is compilation-parse-errors. The function loops over many (about 50) patterns of potential error output and scans the buffer for them repeatedly.

The PR edits the function to use a limited version of re-search-forward. Instead of finding the pattern everywhere, it only looks for the pattern in the first 1024 chars of every line. It seems plausible that real-world compiler warnings would sit close to the beginning of lines.

With the patch the experience (in combination with global-so-long-mode) becomes tolerable; while not lightning fast, Emacs is a lot more responsive in this situation and I as a user retain control to fix the problem, such as comint-clear-buffer etc.

@daviderestivo
Copy link

daviderestivo commented Apr 4, 2021

Emacs does not use GitHub for PRs. This is just a mirror for users convenience. I recommend you send a bug report to bug-gnu-emacs@gnu.org.

@t0yv0
Copy link
Author

t0yv0 commented Apr 4, 2021

I did - thank you!

@t0yv0 t0yv0 closed this Apr 4, 2021
@t0yv0 t0yv0 deleted the t0yv0/fix-shell-compile-freeze-on-long-lines branch April 4, 2021 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants