Subject: bug#43016: replace-region-contents takes a lot of time when called from json-pretty-print-buffer

From: Eli Zaretskii <[email-masked]>
Date: Mon, 24 Aug 2020 13:37:39 +0300

> Date: Mon, 24 Aug 2020 08:25:14 +0000
> From: ljell via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> I have a code which pretty prints data in json:
> 
> ...
>   (with-temp-buffer
>     (insert data)
>     (json-pretty-print-buffer)
>     (write-file "data.json"))
> ...
> 
> This code runs for several minutes (I didn't time it, but it's about 1-2 minutes) with Emacs 27.1  It takes
> several seconds with Emacs 26.  Data is about 1MB on disk in pretty printed elisp format.
> 
> I tried profiling with this result:
> 
>           - progn                                                7486  98%
>            - json-pretty-print-buffer                            7438  98%
>             - json-pretty-print                                  7438  98%
>              - replace-region-contents                           7438  98%
>               + #<compiled 0x3854909>                             198   2%
>            + insert                                                43   0%
>            + write-file                                             5   0%
> 
> Apparently, replace-region-contents  takes 98% of the CPU time.

Thank you for your report and the data.  Is it possible to have the
file with which you've seen this problem?

Tassilo, could you please look into this regression?