Subject: Re: bug#63861: [PATCH] pp.el: New "pretty printing" code

From: Thierry Volpiatto <[email-masked]>
Date: Wed, 07 Jun 2023 16:19:38 +0000

Stefan Monnier <[email-masked]> writes:

>> 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?

No, more or less the same:

(benchmark-run-compiled 1 (pp-buffer))
=> (48.501764747 0 0.0)

I have modified my code so that it can be used outside help, you can
test it with tv/pp-region. Here with always the same test buffer:

(benchmark-run-compiled 1 (tv/pp-region (point-min) (point-max)))
=> (0.259444169 0 0.0)

-- 
Thierry