[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#63861: [PATCH] pp.el: New "pretty printing" code
From: |
Stefan Monnier |
Subject: |
bug#63861: [PATCH] pp.el: New "pretty printing" code |
Date: |
Wed, 07 Jun 2023 11:27:35 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> I tried your code and it looks very slow (but looks nice once printed).
> Testing on my bookmark-alist printed in some buffer.
> Here with a slightly modified version of pp-buffer (not much faster than
> the original one):
>
> (benchmark-run-compiled 1 (pp-buffer))
> => (6.942135047 0 0.0)
> And here with your version (using pp-region):
> (benchmark-run-compiled 1 (pp-buffer))
> => (46.141411097 0 0.0)
>
> For describe variable I use a modified version of `pp` which is very
> fast (nearly instant to pretty print value above) but maybe unsafe with
> some vars, didn't have any problems though, see
> https://github.com/thierryvolpiatto/emacs-config/blob/main/describe-variable.el.
Beside the actual way we choose when to insert \n, the main difference
w.r.t performance tends to come from the fact that the new code relies
on `lisp-indent-line` rather than `lisp-indent-region`.
In many cases it doesn't make much difference performancewise, but
indeed there are cases where the difference is significant (more
specifically where it makes the code O(N²) rather than O(N)).
I've been using the patch below for a while and I should probably
include it the `pp-region` patch.
Can you check whether it helps for your case?
Stefan
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index d44c9d6e23d..9914ededb85 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -876,7 +876,7 @@ lisp-ppss
2 (counting from 0). This is important for Lisp indentation."
(unless pos (setq pos (point)))
(let ((pss (syntax-ppss pos)))
- (if (nth 9 pss)
+ (if (and (not (nth 2 pss)) (nth 9 pss))
(let ((sexp-start (car (last (nth 9 pss)))))
(parse-partial-sexp sexp-start pos nil nil (syntax-ppss sexp-start)))
pss)))
- bug#63861: [PATCH] pp.el: New "pretty printing" code, (continued)
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Visuwesh, 2023/06/09
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Juri Linkov, 2023/06/05
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/07
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Juri Linkov, 2023/06/07
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/07
bug#63861: [PATCH] pp.el: New "pretty printing" code, Thierry Volpiatto, 2023/06/07
- bug#63861: [PATCH] pp.el: New "pretty printing" code,
Stefan Monnier <=
bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/08
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Thierry Volpiatto, 2023/06/08
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/08
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/08
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Thierry Volpiatto, 2023/06/09
- bug#63861: [PATCH] pp.el: New "pretty printing" code, Stefan Monnier, 2023/06/20