smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

Performance issues with sp--save-pre-command-state

Open diogo149 opened this issue 9 years ago • 7 comments

I've noticed performing commands repeatedly (eg. scrolling) in large org-mode buffers cause a huge amount of slow down, and narrowed it down to calling sp--save-pre-command-state in pre-command-hook. In particular, sp-point-in-string.

I've temporarily solved by adding advice around the function to only be called when this-command is a smartparens command (eg. (eq "sp-" (substring (symbol-name this-command) 0 3))) - perhaps something of that sort could be merged in as a permanent solution (if you agree that this is a problem)? Another alternative, based on the comment would be to remove that state. I'd be happy to help out if there's anything I can do.

diogo149 avatar May 11 '15 23:05 diogo149

It must be saved before any command chaning the buffer content is executed as those might break the string symmetry.

Getting rid of it would be best and I already have that as a note somewhere. It's the never-ending problem with strings... when you have "" and put third somewhere it flips the semantics of "in/out". We need to know what the state was before doing magic to the content/balance etc.

However, I have some massive org files (well, 10-15k lines) and I never noticed this. Do you use the stable version or trunk?

Fuco1 avatar May 12 '15 15:05 Fuco1

Are you saying that it would be fine to delete the code for setting sp-point-inside-string? Based on what I've seen, use-inside-string in sp--do-action-p is only set for sp-insert-pair, so perhaps that is when sp-point-in-string should be called?

I use the trunk version and see it happen with a 500KB org file - strangely if the org file is put into a mode that isn't org-mode (fundamental, python, elisp).

diogo149 avatar May 12 '15 17:05 diogo149

For me just moving the point one line up or down around freezes emacs for several seconds. The profiler points to this function being the curlprit. I'll investigate it later even if it kind of breaks my day to day stuff a bit right now.

thomasf avatar May 21 '15 12:05 thomasf

Hmm, it seems that package.el has been ignoring my pinning of smartparens to melpa-stable that is probably why this just started to happen out of "nowhere" for me

thomasf avatar May 21 '15 13:05 thomasf

Any updates? I haven't noticed any similar slowdowns yet.

Fuco1 avatar Oct 31 '15 19:10 Fuco1

I don't have smartparens enabled in text-mode, but when I open a large (1Gb) log text file, emacs hangs and sp--save-pre-command-state seems take much time to finish. Maybe it should run only in buffers with smartparens enabled?

- sp--save-pre-command-state                                     4340  73%
 - sp-point-in-string                                            4340  73%
  + sp--syntax-ppss                                              4340  73%
+ command-execute                                                1550  26%
+ redisplay_internal (C function)                                  21   0%
+ timer-event-handler                                               2   0%
+ ...                                                               0   0%

Yevgnen avatar Apr 26 '19 08:04 Yevgnen

@Yevgnen Yes that sounds reasonable.

Fuco1 avatar Apr 29 '19 09:04 Fuco1