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: Wed, 17 Dec 2014 04:41:49 +0200 Message-ID: <5490ED6D.5080808@yandex.ru> References: <86a92oddfp.fsf@yandex.ru> <86mw6nkc6n.fsf@yandex.ru> <54904241.8010000@yandex.ru> <5490BFCD.5050505@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1418784163 23070 80.91.229.3 (17 Dec 2014 02:42:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Dec 2014 02:42:43 +0000 (UTC) Cc: 19390@debbugs.gnu.org To: bruce.connor.am@gmail.com, Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 17 03:42:35 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 1Y14ZA-00061a-AV for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 03:42:20 +0100 Original-Received: from localhost ([::1]:47655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y14Z9-0007JV-Ib for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Dec 2014 21:42:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y14Yz-0007JO-RK for bug-gnu-emacs@gnu.org; Tue, 16 Dec 2014 21:42:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y14Ys-0003JQ-Av for bug-gnu-emacs@gnu.org; Tue, 16 Dec 2014 21:42:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y14Ys-0003JM-8I for bug-gnu-emacs@gnu.org; Tue, 16 Dec 2014 21:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y14Yr-0000rX-PY for bug-gnu-emacs@gnu.org; Tue, 16 Dec 2014 21:42:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Dec 2014 02:42: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.14187841173303 (code B ref 19390); Wed, 17 Dec 2014 02:42:01 +0000 Original-Received: (at 19390) by debbugs.gnu.org; 17 Dec 2014 02:41:57 +0000 Original-Received: from localhost ([127.0.0.1]:48294 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y14Ym-0000rC-8U for submit@debbugs.gnu.org; Tue, 16 Dec 2014 21:41:56 -0500 Original-Received: from mail-wg0-f42.google.com ([74.125.82.42]:46521) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y14Yj-0000r2-G8 for 19390@debbugs.gnu.org; Tue, 16 Dec 2014 21:41:54 -0500 Original-Received: by mail-wg0-f42.google.com with SMTP id k14so2860171wgh.29 for <19390@debbugs.gnu.org>; Tue, 16 Dec 2014 18:41:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=BjlF4dE80AbvhX+Wi9Qe8BveFFtm7Ykfp+4ubbEf0Og=; b=PByMWVwzpZhd+iVWKX0NcPWF5YDx7dROUdqTQ42z75UxoZQVhKRJ1ORki9cU7jIuqr JqW6hGzFCAdS6ScyJU/cmpXIKPSLhwwJVV7aQ578tOJTcF9nUtBJ/+9mI8Jyt7RVv8nQ DYeFzT9Stx6h5LkGDeu9JxiF/e2aQ8KhktP8ARSQqhJDXHU0yxVOUsLtySp/LOA5sNVx tQ/GTFISGIcRpfp9fE+YOw8qSxW5n8veax0F74Bs0qLwXjBdo3Z8FXRplYOb84ikNao0 P/Ja60wedEsuktC3StEKvuy+1Khyi6pK7tHWhDj2JnMpje9Lu5X2dn8Frq6NHO5nW7Cw m/Tw== X-Received: by 10.180.182.199 with SMTP id eg7mr9733976wic.17.1418784112625; Tue, 16 Dec 2014 18:41:52 -0800 (PST) Original-Received: from [192.168.1.2] ([82.102.93.58]) by mx.google.com with ESMTPSA id j2sm3260147wjs.28.2014.12.16.18.41.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Dec 2014 18:41:52 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 In-Reply-To: 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:97427 Archived-At: Speaking of non-radical optimizations, this takes the packages activation time of 2.1 s (after the last small patch) down to 300 ms. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 60beebd..30b5fb2 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -527,7 +527,7 @@ Return the max version (as a string) if the package is held at a lower version." (let* ((old-lp load-path) (autoloads-file (expand-file-name (format "%s-autoloads" name) pkg-dir)) - (loaded-files-list (package--list-loaded-files pkg-dir))) + (loaded-files-list (package--list-loaded-files name pkg-dir))) (with-demoted-errors (format "Error loading %s: %%s" name) (load autoloads-file nil t)) (when (and (eq old-lp load-path) @@ -555,36 +555,36 @@ Return the max version (as a string) if the package is held at a lower version." ;; Don't return nil. t)) -(defun package--list-loaded-files (dir) +(defun package--list-loaded-files (name dir) "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* ((old-dir-re (concat "\\`" + (regexp-quote (file-truename package-user-dir)) + "/" (regexp-quote (symbol-name name)))) + (filtered-history (cl-loop for entry in load-history + for file = (car entry) + when (string-match-p old-dir-re file) + collect (file-name-sans-extension file))) + (files (directory-files-recursively dir "\\`[^\\.].*\\.el\\'")) + (files-re (concat "/" + (regexp-opt + (mapcar (lambda (x) + (file-name-sans-extension + (file-relative-name x dir))) + files)) + "\\'")) + list-of-conflicts) + ;; List all the matching files from the load history, in + ;; historical order. + (dolist (file filtered-history) + (when (string-match files-re file) + (cl-pushnew (substring (match-string 0 file) 1) + 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.