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

Don't indent already indented output when pretty-printing #2023

Closed
ak-coram opened this issue Jul 3, 2017 · 2 comments
Closed

Don't indent already indented output when pretty-printing #2023

ak-coram opened this issue Jul 3, 2017 · 2 comments

Comments

@ak-coram
Copy link
Contributor

ak-coram commented Jul 3, 2017

Note: Currently I believe the issue is with Cider, but it also relates
to recent changes on the master branch of Emacs, so I'm not entirely
sure this is the right place to post this report. I think this is more
of a feature request anyway.

Emacs has introduced lisp-indentation changes which don't reparse
the code as often as before and rely on previous parse-state to
improve performance. I believe this change is causing performance
issues with cider-emit-into-popup-buffer, when pretty-printing
non-trivial amounts of data.

I profiled Emacs and found that it spends most of the time garbage
collecting and lisp-indent-calc-next during pretty-printing.

I've also found that if I comment out the indent-sexp call from the
cider-emit-into-popup-buffer function, the issue is gone.

I'm not really sure what other features cider-emit-into-popup-buffer
is used for (except pretty-printing), but don't pretty-print functions
already indent their output? Why is there a need for Emacs to indent
the output again?

If you agree, I can submit a pull request for
cider-emit-into-popup-buffer with an optional parameter to inhibit
indentation.

@bbatsov
Copy link
Member

bbatsov commented Jul 7, 2017

Emacs has introduced lisp-indentation changes which don't reparse
the code as often as before and rely on previous parse-state to
improve performance. I believe this change is causing performance
issues with cider-emit-into-popup-buffer, when pretty-printing
non-trivial amounts of data.

Hmm, I didn't notice this at all.

I profiled Emacs and found that it spends most of the time garbage
collecting and lisp-indent-calc-next during pretty-printing.

It's often a good idea to increase the GC limit (which is super conservative by default) - see http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/

I'm not really sure what other features cider-emit-into-popup-buffer
is used for (except pretty-printing), but don't pretty-print functions
already indent their output? Why is there a need for Emacs to indent
the output again?

We have to see all usages in the codebase - I think it might be used somewhere for non-pretty printed results.

If you agree, I can submit a pull request for
cider-emit-into-popup-buffer with an optional parameter to inhibit
indentation.

Sure. At the very list this can be added just for the cases that really need it (if any).

@bbatsov
Copy link
Member

bbatsov commented Jul 7, 2017

I see there are just 5 usages of this function in the entire codebase, so it should be easy for you to find your way. Seems to me the only usage that really needs the indent-sexp is this one:

(defun cider--emit-interactive-eval-output (output repl-emit-function)
  "Emit output resulting from interactive code evaluation.

The OUTPUT can be sent to either a dedicated output buffer or the current
REPL buffer.  This is controlled by `cider-interactive-eval-output-destination'.
REPL-EMIT-FUNCTION emits the OUTPUT."
  (pcase cider-interactive-eval-output-destination
    (`output-buffer (let ((output-buffer (or (get-buffer cider-output-buffer)
                                             (cider-popup-buffer cider-output-buffer t))))
                      (cider-emit-into-popup-buffer output-buffer output)
                      (pop-to-buffer output-buffer)))
    (`repl-buffer (funcall repl-emit-function output))
    (_ (error "Unsupported value %s for `cider-interactive-eval-output-destination'"
              cider-interactive-eval-output-destination))))

Take a look yourself and make the changes accordingly. Some of this uses of this function don't even output sexps, so there this is completely worthless. An oversight on our part I guess.

ak-coram added a commit to ak-coram/cider that referenced this issue Jul 9, 2017
- Add optional inhibit-indent argument to cider-emit-into-popup-buffer.

- Inhibit indentation where output is already indented (pprint) or not sexps.
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

2 participants