From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: George Plymale II Newsgroups: gmane.emacs.devel Subject: Re: Loading a package applies automatically to future sessions? Date: Sat, 10 Feb 2018 20:23:40 -0500 Message-ID: References: <837erl2gxo.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1518312163 19569 195.159.176.226 (11 Feb 2018 01:22:43 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Feb 2018 01:22:43 +0000 (UTC) Cc: radon.neon@gmail.com, monnier@IRO.UMontreal.CA, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 11 02:22:38 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ekgLI-0003H6-WE for ged-emacs-devel@m.gmane.org; Sun, 11 Feb 2018 02:22:09 +0100 Original-Received: from localhost ([::1]:59001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekgNI-0006pU-VH for ged-emacs-devel@m.gmane.org; Sat, 10 Feb 2018 20:24:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekgN4-0006hk-88 for emacs-devel@gnu.org; Sat, 10 Feb 2018 20:24:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekgN0-0000LQ-RL for emacs-devel@gnu.org; Sat, 10 Feb 2018 20:23:58 -0500 Original-Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:47027) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ekgN0-0000KP-Ge for emacs-devel@gnu.org; Sat, 10 Feb 2018 20:23:54 -0500 Original-Received: by mail-pl0-x243.google.com with SMTP id 36so3255178ple.13 for ; Sat, 10 Feb 2018 17:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orbitalimpact.com; s=google; h=from:to:cc:subject:in-reply-to:date:message-id:mime-version; bh=Nm5D//XSHOJNwCMzfOOTIBmx9MBwcqrDGdqe08zFJ5U=; b=hlWsF9OI/pFDqO0rUCqhQKGGxAFNuVC41REsR9GsKZkzxhxPabyRRSTJDwe1bnh1LC X7KAP4AEgFtOPDjfnoEq4mLYa3+dULslE/IN4VE6C0sm+bfy38mXBsz78gfsYuXhD0fX d52ZhZ26x5TJaz8nzjDVLBRkb3NDwl2tjZIh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:date:message-id :mime-version; bh=Nm5D//XSHOJNwCMzfOOTIBmx9MBwcqrDGdqe08zFJ5U=; b=Sxgcmx/T1LNQLWU2UouOXLPs84VeocLjNheSoPiaD6MYNMr0y9SSUBXCxYdizFGTsX rOzRkeWPsetSFBZOc3jvt/YZao+FdCWVKvkZWAjsxiQJcJctiniLtOvd4LXjGgCaYLK8 nTPmkCzKEhwyitXTU3BDYBoSUg2ayXkqxn5e6+RRhPweB9dVjfOgjy/ojMjIKA6UZC/5 6el5bMJ3oyGBkC6ATDJl/PalLQM9bGhUPgUzvST27NYcHPiIiyX0qkOJRFCjuAniUz24 wZyUX2fyhPzAKwtyFKLzEJmzA6/DPEJW+UpjDpOJDwvmHMuupOJIQyod/EgQnleTxpbo oWLQ== X-Gm-Message-State: APf1xPCXrxYdDmuOnscDHR2qOQo0fZBKFZqpIzDKiCpN+UkY/cwyoEvQ aKt8ocvQyFXD8BtuYZn/OFN6T+KGd2E= X-Google-Smtp-Source: AH8x224s4qe2nTd+QePxQ3DPZRnZlEaCkP8D689AFcYIjbkTlVq65kUMTAlrdFvMQSDmUPzxfhQLCQ== X-Received: by 2002:a17:902:7c18:: with SMTP id x24-v6mr6733071pll.432.1518312233299; Sat, 10 Feb 2018 17:23:53 -0800 (PST) Original-Received: from lehi.dev.orbitalimpact.com (ip-52-36-244-173.west.us.northamericancoax.com. [173.244.36.52]) by smtp.gmail.com with ESMTPSA id c8sm14788341pfm.130.2018.02.10.17.23.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Feb 2018 17:23:52 -0800 (PST) In-Reply-To: <837erl2gxo.fsf@gnu.org> (message from Eli Zaretskii on Sat, 10 Feb 2018 14:00:03 +0200) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222655 Archived-At: --=-=-= Content-Type: text/plain Hi, Sorry, I don't mean to hijack the conversation, but speaking of patches, Stefan gave me an updated version of his patch recently. This one allows byte-compilation of his ~/.emacs.d/package-fastpath.el file. I asked him in private if he needs any further feedback several days ago, but I did not receive a reply from him so I'll assume that it's okay to re-post his patch here on the list. I have attached two patches. One is the patch that he originally made which applies to the Emacs trunk, and the other is for Emacs 25.3. Which is my current working Emacs version. If anyone could provide further feedback to Stefan to help him improve this patch, I'm sure he would appreciate it and I would as well. So far, I haven't noticed any significant performance improvements from his patch. Although, with the byte-compilation in place (along with some other optimizations to my startup code) my init time has gone down to 1.1 seconds. It was 1.4 seconds last time I reported about it on this thread, I think. Also, I have noticed (and I forgot to tell Stefan about this in our private thread) that the bug which I noticed regarding info files from ELPA is gone. I.e., this bug (which I reported on Jan 31): "The info files for my packages from ELPA are all missing in the info Directory node." is no longer happening, so I guess Stefan has fixed it in this most recent patch. Yay! Unfortunately, I had more problems with byte-compilation when I had the gh.el package installed. package-fastpath.el would refuse to byte-compile. I have since uninstalled this package since I only had one other package which was dependent on it and I haven't used it recently. Stefan's patch probably needs some work in order to properly deal with strange autoload files. However, the developer of gh.el is currently trying to make its autoload file a bit lighter so this may not be a concern much longer. In any case, I think that Stefan's patch here is still the best solution to the original problem posed by RMS at the inception of this thread. It just needs some work. It is also improving startup time quite noticeably for myself and I am sure that it will for others as well. Thanks, - George Plymale II --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=stefans_2nd_patch_for_emacs_trunk.patch Content-Transfer-Encoding: quoted-printable Content-Description: Stefan's 2nd patch for package.el (trunk version) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 71d1c41ec3..b918eb5dfe 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -676,6 +676,8 @@ package--activate-autoloads-and-load-path (defvar Info-directory-list) (declare-function info-initialize "info" ()) =20 +(defvar package--fastpath-pkgs t) + (defun package--load-files-for-activation (pkg-desc reload) "Load files for activating a package given by PKG-DESC. Load the autoloads file, and ensure `load-path' is setup. If @@ -718,7 +720,10 @@ package-activate-1 (message "Unable to activate package `%s'.\nRequired package `= %s-%s' is unavailable" name (car req) (package-version-join (cadr req))) (throw 'exit nil)))) - (package--load-files-for-activation pkg-desc reload) + (if (listp package--fastpath-pkgs) + ;; We're only collecting the set of packages to activate! + (push pkg-desc package--fastpath-pkgs) + (package--load-files-for-activation pkg-desc reload)) ;; Add info node. (when (file-exists-p (expand-file-name "dir" pkg-dir)) ;; FIXME: not the friendliest, but simple. @@ -3468,6 +3473,67 @@ package-list-packages-no-fetch (interactive) (list-packages t)) =20 +;;;; Fast-path for activation! + +(defcustom package-fastpath-file (locate-user-emacs-file "package-fastpath= .el") + "Location of the file used to speed up activation of packages at startup= ." + :type 'file) + +(defun package-fastpath-refresh () + "(Re)Generate the `package-fastpath-file'." + (interactive) + (package-initialize 'no-activate) + (require 'info) + (let ((package--fastpath-pkgs ()) + ;; Pretend we haven't activated anything yet! + (package-activated-list ()) + (Info-directory-list '(""))) + (dolist (elt package-alist) + (condition-case err + (package-activate (car elt)) + ;; Don't let failure of activation of a package arbitrarily stop + ;; activation of further packages. + (error (message "%s" (error-message-string err))))) + (setq package--fastpath-pkgs (nreverse package--fastpath-pkgs)) + (with-temp-file package-fastpath-file + (emacs-lisp-mode) + (insert ";;; FastPath file to speed up package activation at startup= -*- lexical-binding:t -*-\n") + (insert ";; =C2=A1=C2=A1 This file is autogenerated, DO NOT EDIT !!\= n\n") + (dolist (pkg package--fastpath-pkgs) + (let* ((file + ;; Prefer uncompiled files (and don't accept .so files). + (let ((load-suffixes '(".el" ".elc"))) + (locate-library (package--autoloads-file-name pkg)))) + (pfile (prin1-to-string file))) + (insert "(let ((load-file-name " pfile "))\n") + (insert-file-contents file) + ;; FIXME: We also need to setup the Info-directory-list! + (while (search-forward "#$" nil 'move) + (unless (nth 8 (syntax-ppss)) + (replace-match pfile t t))) + (unless (bolp) (insert "\n")) + (insert ")\n"))) + (pp `(setq package-activated-list + (append ',(mapcar #'package-desc-name package--fastpath-p= kgs) + package-activated-list)) + (current-buffer)) + (let ((info-dirs (butlast Info-directory-list))) + (when info-dirs + (pp `(progn (require 'info) + (info-initialize) + (setq Info-directory-list + (append ',info-dirs Info-directory-list))) + (current-buffer)))) + ;; Use `\s' instead of a space character, so this code chunk is not + ;; mistaken for an actual file-local section of package.el. + (insert " +;; Local\sVariables: +;; version-control: never +;; no-byte-compile: nil +;; no-update-autoloads: t +;; End: +")))) + (provide 'package) =20 ;;; package.el ends here --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=stefans_2nd_patch_for_emacs_25.3.patch Content-Transfer-Encoding: quoted-printable Content-Description: Stefan's 2nd patch for package.el (25.3 stable version) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 32200227de..cbb326f26e 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -656,6 +656,8 @@ PKG-DESC is a `package-desc' object." (defvar Info-directory-list) (declare-function info-initialize "info" ()) =20 +(defvar package--fastpath-pkgs t) + (defun package--load-files-for-activation (pkg-desc reload) "Load files for activating a package given by PKG-DESC. Load the autoloads file, and ensure `load-path' is setup. If @@ -696,7 +698,10 @@ correspond to previously loaded files (those returned = by (unless (package-activate (car req)) (error "Unable to activate package `%s'.\nRequired package `%s-%= s' is unavailable" name (car req) (package-version-join (cadr req)))))) - (package--load-files-for-activation pkg-desc reload) + (if (listp package--fastpath-pkgs) + ;; We're only collecting the set of packages to activate! + (push pkg-desc package--fastpath-pkgs) + (package--load-files-for-activation pkg-desc reload)) ;; Add info node. (when (file-exists-p (expand-file-name "dir" pkg-dir)) ;; FIXME: not the friendliest, but simple. @@ -3437,6 +3442,67 @@ The list is displayed in a buffer named `*Packages*'= ." (interactive) (list-packages t)) =20 +;;;; Fast-path for activation! + +(defcustom package-fastpath-file (locate-user-emacs-file "package-fastpath= .el") + "Location of the file used to speed up activation of packages at startup= ." + :type 'file) + +(defun package-fastpath-refresh () + "(Re)Generate the `package-fastpath-file'." + (interactive) + (package-initialize 'no-activate) + (require 'info) + (let ((package--fastpath-pkgs ()) + ;; Pretend we haven't activated anything yet! + (package-activated-list ()) + (Info-directory-list '(""))) + (dolist (elt package-alist) + (condition-case err + (package-activate (car elt)) + ;; Don't let failure of activation of a package arbitrarily stop + ;; activation of further packages. + (error (message "%s" (error-message-string err))))) + (setq package--fastpath-pkgs (nreverse package--fastpath-pkgs)) + (with-temp-file package-fastpath-file + (emacs-lisp-mode) + (insert ";;; FastPath file to speed up package activation at startup= -*- lexical-binding:t -*-\n") + (insert ";; =C2=A1=C2=A1 This file is autogenerated, DO NOT EDIT !!\= n\n") + (dolist (pkg package--fastpath-pkgs) + (let* ((file + ;; Prefer uncompiled files (and don't accept .so files). + (let ((load-suffixes '(".el" ".elc"))) + (locate-library (package--autoloads-file-name pkg)))) + (pfile (prin1-to-string file))) + (insert "(let ((load-file-name " pfile "))\n") + (insert-file-contents file) + ;; FIXME: We also need to setup the Info-directory-list! + (while (search-forward "#$" nil 'move) + (unless (nth 8 (syntax-ppss)) + (replace-match pfile t t))) + (unless (bolp) (insert "\n")) + (insert ")\n"))) + (pp `(setq package-activated-list + (append ',(mapcar #'package-desc-name package--fastpath-p= kgs) + package-activated-list)) + (current-buffer)) + (let ((info-dirs (butlast Info-directory-list))) + (when info-dirs + (pp `(progn (require 'info) + (info-initialize) + (setq Info-directory-list + (append ',info-dirs Info-directory-list))) + (current-buffer)))) + ;; Use `\s' instead of a space character, so this code chunk is not + ;; mistaken for an actual file-local section of package.el. + (insert " +;; Local\sVariables: +;; version-control: never +;; no-byte-compile: nil +;; no-update-autoloads: t +;; End: +")))) + (provide 'package) =20 ;;; package.el ends here --=-=-=--