Subject: Re: bug#62364: 28.2; savehist file becomes quadratic when used with kill-ring and evil-yank-rectangle

From: Eli Zaretskii <[email-masked]>
Date: Thu, 23 Mar 2023 10:54:19 +0200

> Cc: [email-masked]
> From: Aaron Zeng <[email-masked]>
> Date: Tue, 21 Mar 2023 17:30:40 -0400
> 
> 
> Serializing text properties on savehist variables can cause quadratic
> behavior due to large shared data structures.  The motivating scenario
> is with `kill-ring' added to `savehist-additional-variables', and
> `evil-mode' enabled.  `evil-yank-rectangle' copies a string and sets
> its `yank-handler' text property to a structure containing a list of
> every line of the copied string.  When `savehist-save' runs, this text
> property can get serialized linearly many times (depending on the
> other text properties in different substrings of the copied text), and
> the property is as long as the text itself, which results in a
> quadratic amount of data serialization.
> 
> For example:
> 
> 1. emacs -Q
> 2. Enable savehist-mode and add kill-ring to savehist-additional-variables
> 3. Enable evil-mode (I'm using Evil version evil-git-9584081cf)
> 4. Open a medium-size file with several hundred lines
> 5. Copy the whole file as a rectangle, by pressing C-v G $ y
> 6. M-x savehist-save
> 
> On an OCaml source file with about 400 lines, savehist-save took over
> 5 seconds and resulted in a >70MB savehist file.
> 
> A suggested patch is below.  For comparison, with the patch,
> savehist-save takes less than a second and results in a 160kB savehist
> file.

Lars, Stefan, any comments?  Are there any downsides to binding
print-circle to a non-nil value here?