Subject: bug#19390: 25.0.50; `package-activate' is too slow

From: Artur Malabarba <[email-masked]>
Date: Tue, 16 Dec 2014 11:42:09 -0200

As for low-hanging fruits in `package--list-loaded-files', there are
two I can think of.

1. If `load-history' stored `file-truename's (relative to "/"),
instead of just absolute file names, then that would avoid a lot of
calls to `file-truename'. This, I suspect, is the bigger performance
issue.
2. Creating the `history' variable as below is a problem.

(mapcar (lambda (x) (file-name-sans-extension
                                  (file-truename (car x))))
                    load-history)

This lambda is called a lot more times than necessary, because most
entries in load-history are useless here. But we need to do this to be
able to reliably compare file names. Ideally, there would be another
variable, like `load-history-truename', which is modified in parellel
with `load-history' and *only* stores the truename of files listed in
`load-history' (no need to store all that extra information). Then we
could just use this variable unmodified.

Implementing 2. would also fix 1.

2014-12-16 11:26 GMT-02:00 Artur Malabarba <[email-masked]>:
> I didn't notice anything as aggravating as the report, but I agree my
> latest patch is a performance concern.
>
> The proposed patch looks good, just a couple of notes:
>
> 1. I'd use RELOAD for the name of the optional argument.
> 2. Since this function now takes a second (somewhat non-trivial
> argument), we should add a docstring to it:
>
> "Activate package given by PKG-DESC, even if it was already active.
> If RELOAD is non-nil, also `load' any files inside the package which
> correspond to previously loaded files (those returned by
> `package--list-loaded-files').
>
> This is called internally by `package-activate'."