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

Much lag for large files (>4000 lines) #369

Closed
molgrum opened this issue Sep 8, 2016 · 13 comments
Closed

Much lag for large files (>4000 lines) #369

molgrum opened this issue Sep 8, 2016 · 13 comments

Comments

@molgrum
Copy link

molgrum commented Sep 8, 2016

As the title says, tested on Windows 10. It is very tedious to work because every character I type has 1-2 second delay to it. If more info is needed I can do profiling.

@srt19170
Copy link

Ditto.

@dgutov
Copy link
Collaborator

dgutov commented Nov 21, 2016

Please try:

(setq blink-matching-paren nil)

@srt19170
Copy link

That seems to have fixed the problem for me (or at least so far!) Thanks!

@srt19170
Copy link

Although the blink-matching-paren fixed some issues, I'm still having problems with large files. Doing a profile during a couple of long hangs revealed these as the top CPU users:

+ completion-pcm--all-completions                                  25   2%
+ js2-get-token                                                    28   2%
+ js2-parse-member-expr-tail                                       30   2%
+ js2-visit-ast                                                    56   4%
+ js2-match-token                                                  56   4%
+ js2-skip-line                                                    77   6%
+ js2-get-token-internal-1                                        128  10%
+ js2-get-token-internal                                          172  13%
  Automatic GC                                                    183  14%

This might be slow even without the GCs, but it seems like something in get-token-internal is creating a lot of garbage?

@dgutov
Copy link
Collaborator

dgutov commented Dec 15, 2016

Just how large are the files we are talking about?

@srt19170
Copy link

The one I ran the profile on is 6000 lines. I can provide it to you (offline) for testing if that would help.

@dgutov
Copy link
Collaborator

dgutov commented Dec 15, 2016

Before we do that, have you tried reproducing the problem starting with emacs -Q?

The scenario would look something like this:

emacs -Q -L ~/.emacs.d/elpa/js2-mode-???/
(require 'js2-mode)
find-file ....
M-x js2-mode
(your steps here)

@srt19170
Copy link

Yes, I get the same behavior in -Q.

@dgutov
Copy link
Collaborator

dgutov commented Dec 15, 2016

All right, please send me the file. My email is at the top of js2-mode.el.

@dgutov
Copy link
Collaborator

dgutov commented Dec 15, 2016

Thanks, I see it there. Seeing as the reproduction scenario involves typing characters from electric-indent-chars, electric-indent-mode (on by default) is involved.

Ultimately, it's a bug in js--multi-line-declaration-indentation caused by a faulty translation from js2-mode indentation code. You can apply this patch to your Emacs:

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 6d995a0..0ba7aac 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1851,7 +1851,8 @@ js--multi-line-declaration-indentation
   "Helper function for `js--proper-indentation'.
 Return the proper indentation of the current line if it belongs to a declaration
 statement spanning multiple lines; otherwise, return nil."
-  (let (at-opening-bracket)
+  (let (forward-sexp-function ; use Lisp version even in js2-mode
+        at-opening-bracket)
     (save-excursion
       (back-to-indentation)
       (when (not (looking-at js--declaration-keyword-re))

And I'll try to get it into the upcoming Emacs release (25.2).

@srt19170
Copy link

I'm not sure how I'm "supposed" to patch Emacs, but putting a fixed version of the function into my .emacs file seemed to work, because the hangup is now gone.

Thanks a bunch, Dmitri! Really appreciate the effort!

@dgutov
Copy link
Collaborator

dgutov commented Dec 16, 2016

I'm not sure how I'm "supposed" to patch Emacs

You apply the patch the sources, and rebuild. 😛 If Emacs was built by your distribution, it's harder, of course.

putting a fixed version of the function into my .emacs file seemed to work

That works as well. And yet another option is to define an around-advice for this function, with a let-binding for the aforementioned variable.

You're welcome!

@dgutov
Copy link
Collaborator

dgutov commented Dec 16, 2016

get it into the upcoming Emacs release (25.2)

And done.

@dgutov dgutov closed this as completed Dec 16, 2016
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

No branches or pull requests

3 participants