From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#19390: 25.0.50; `package-activate' is too slow Date: Thu, 18 Dec 2014 02:14:22 +0200 Message-ID: <868ui5ervl.fsf@yandex.ru> References: <86a92oddfp.fsf@yandex.ru> <86mw6nkc6n.fsf@yandex.ru> <54904241.8010000@yandex.ru> <5490BFCD.5050505@yandex.ru> <5490ED6D.5080808@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1418861732 16933 80.91.229.3 (18 Dec 2014 00:15:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 18 Dec 2014 00:15:32 +0000 (UTC) Cc: 19390@debbugs.gnu.org To: Artur Malabarba Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 01:15:21 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y1OkT-0000BA-09 for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Dec 2014 01:15:21 +0100 Original-Received: from localhost ([::1]:52043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1OkR-0005Se-TJ for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 19:15:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1OkI-0005S3-Eh for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 19:15:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1OkA-0002Dc-US for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 19:15:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1OkA-0002Ct-R9 for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 19:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y1OkA-0002MS-1S for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 19:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Dec 2014 00:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19390 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19390-submit@debbugs.gnu.org id=B19390.14188616699022 (code B ref 19390); Thu, 18 Dec 2014 00:15:01 +0000 Original-Received: (at 19390) by debbugs.gnu.org; 18 Dec 2014 00:14:29 +0000 Original-Received: from localhost ([127.0.0.1]:49352 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Ojd-0002LR-AW for submit@debbugs.gnu.org; Wed, 17 Dec 2014 19:14:29 -0500 Original-Received: from mail-wi0-f171.google.com ([209.85.212.171]:61977) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Oja-0002LH-It for 19390@debbugs.gnu.org; Wed, 17 Dec 2014 19:14:27 -0500 Original-Received: by mail-wi0-f171.google.com with SMTP id bs8so38988wib.4 for <19390@debbugs.gnu.org>; Wed, 17 Dec 2014 16:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=gVK6TFdKwL+FT1ne+aR1FQPHMTypK2dQxX2LgGZ4G24=; b=AJ8DjpmxOl8ZSUMoSKNEn5q1/AG57H8lGKJANA0F1GPtR/j3MRPISeXdCIADlP6R9i EMzLh8yDDYWveIZSgGnDcJXjwJEisH+rJtLJj3v0eWdebpC/i/vEt290xivTyUnBCnaS nYU1/GNdGZO1nt/yUVaIonmscmIqRdVo+DZ4KJjTBnqTxqQ1LOMieDDHF+5b4/bc6b8r uzYBJdJ5zf2oWZuLVAYhcTvowLgg1S3n7XfvWM5L3bVgMwUJPDbkPiuTTN5AqUmrRDbL WI4hMbP/HuDLPDqAIuAOz0I1l7c2NjT8uklY9ND4qQiCxW7EfGSlu3ZBg1W181QJso/T /WgA== X-Received: by 10.180.93.37 with SMTP id cr5mr19273469wib.76.1418861665647; Wed, 17 Dec 2014 16:14:25 -0800 (PST) Original-Received: from axl ([82.102.93.58]) by mx.google.com with ESMTPSA id dp8sm22725918wib.20.2014.12.17.16.14.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 17 Dec 2014 16:14:25 -0800 (PST) In-Reply-To: (Artur Malabarba's message of "Wed, 17 Dec 2014 08:47:57 -0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.51 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97475 Archived-At: Artur Malabarba writes: > This will fail if the previously loaded version wasn't installed in the > package-user-dir, which, again, is the case for built-in packages. This > also includes manually installed packages, which we may or may not care > about supporting. Good point, thanks. Here's the patch without the initial filtering part. Still an improvement over the current code (0.6s vs 2.1s on my machine). (And it drops the use of `file-name-sans-extension'). We could also check the `provide' value in each entry's alist, to make sure of the match, probably at no major cost. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 60beebd..90bb514 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -559,32 +559,26 @@ Return the max version (as a string) if the package is held at a lower version." "Recursively list all files in DIR which correspond to loaded features. Returns the `file-name-sans-extension' of each file, relative to DIR, sorted by most recently loaded last." - (let* ((history (mapcar (lambda (x) (file-name-sans-extension (car x))) - load-history)) - (dir (file-truename dir)) - ;; List all files that have already been loaded. - (list-of-conflicts - (remove - nil - (mapcar - (lambda (x) (let* ((file (file-relative-name x dir)) - ;; Previously loaded file, if any. - (previous - (ignore-errors - (file-name-sans-extension - (file-truename (find-library-name file))))) - (pos (when previous (member previous history)))) - ;; Return (RELATIVE-FILENAME . HISTORY-POSITION) - (when pos - (cons (file-name-sans-extension file) (length pos))))) - (directory-files-recursively dir "\\`[^\\.].*\\.el\\'"))))) - ;; Turn the list of (FILENAME . POS) back into a list of features. Files in - ;; subdirectories are returned relative to DIR (so not actually features). - (let ((default-directory (file-name-as-directory dir))) - (mapcar (lambda (x) (file-truename (car x))) - (sort list-of-conflicts - ;; Sort the files by ascending HISTORY-POSITION. - (lambda (x y) (< (cdr x) (cdr y)))))))) + (let* ((files (directory-files-recursively dir "\\`[^\\.].*\\.el\\'")) + (files-re (concat "/" + (regexp-opt + (mapcar (lambda (x) + (file-relative-name x dir)) + files) + t) + "c?\\'")) + list-of-conflicts) + ;; List all the matching files from the load history, in + ;; historical order. + (dolist (entry load-history) + (let ((file (car entry))) + (when (string-match files-re file) + (cl-pushnew (substring (match-string 1 file) 0 -3) + list-of-conflicts + :test #'equal)))) + ;; Files in subdirectories are returned relative to DIR (so not + ;; actually features). + list-of-conflicts)) (defun package-built-in-p (package &optional min-version) "Return true if PACKAGE is built-in to Emacs.