Subject: Re: bug#36877: 25.3; uniquify renaway uniquify-managed list

From: Noam Postavsky <[email-masked]>
Date: Thu, 08 Aug 2019 20:47:31 -0400

David Biesack <[email-masked]> writes:

> The list uniquified-managed sometimes starts to grow in an unmanaged manner (I suspect exponentially) after running
> Emacs for a few days. My work involves heavily editing many files named "openapi.yaml" in about 20 different
> directories, often switching git branches so I need to revisit (M-x revert-buffer) these files a lot.
>
> After a few days, I noticed opening new openapi.yaml files started to slow down dramatically - there would be several
> seconds of delay, then tens of seconds. I narrowed this to uniquify. In my buffers, the local variable
> uniquified-managed is more than 100,000 items long, with many duplicate items.

Looks like the only place where uniquified-managed is set to non-nil is
by uniquify-rationalize, so could you run with the advice below and post
the backtrace you get with it?

    (defconst bug-36877-dup-table (make-hash-table :test 'eq))
    (defun bug-36877-debug-fix-list-dups (fix-list)
      (clrhash bug-36877-dup-table)
      (dolist (item fix-list)
        (let ((buf (uniquify-item-buffer item)))
          (if (gethash buf bug-36877-dup-table)
              (progn (debug nil "Adding duplicate to uniquify list!" item)
                     ;; Just once.
                     (advice-remove 'uniquify-rationalize
                                    #'bug-36877-debug-fix-list-dups))
            (puthash buf item bug-36877-dup-table)))))
    (advice-add 'uniquify-rationalize :before #'bug-36877-debug-fix-list-dups)