unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Loading package data using with-current-buffer
@ 2023-08-26  8:42 Christoph
  0 siblings, 0 replies; only message in thread
From: Christoph @ 2023-08-26  8:42 UTC (permalink / raw)
  To: emacs-devel

I am currently investigating some slow down in my Emacs startup speed
and noticed, that several packages, like `bookmark' or `saveplace' are
using `with-current-buffer' to load data from disk.  Others, like
`abbrev', `recentf', or `savehist' are using `load' directly.  There
are also packages like `projectile' (not distributed with Emacs) which
is using `with-temp-buffer' to load data.

I am configuring many of these packages right away and make them load
their data.  But `with-current-buffer' comes with the downside, that
the buffer used for loading the data runs all its associated hooks,
which might be quite heavy.  In my case, when I am loading the
bookmarks, `magit' is loaded (because I am using
`magit-auto-revert-mode'), `undo-tree' writes data to disk (because it
uses the `kill-buffer-hook') and many more things.  In addition,
because my bookmark files ends in .eld (since it is lisp data), the
`prog-mode' and `emacs-lisp-mode' are used for the buffer, which might
load many more packages.  I "solved" the last part, by renaming my
bookmarks file.

Is there any rational behind using `with-current-buffer', rather than
`with-temp-buffer' to load data from disk?  I understand that using
`find-file-noselect' in conjunction with `with-current-buffer' might
interact with the user, if there are problems loading the file.  For
`with-temp-buffer', one might use `insert-file-contents', which does
not provide such interaction.  So if it is not desirable to load the
data using `with-temp-buffer' if the user interactively loads the data
from disk, wouldn't it at least make sense to load the data using
`with-temp-buffer' if loading happens non-interactively?  But even if
loading happens interactively, I think it still shouldn't trigger all
the hooks and loading all the packages required to actually work with
the bookmark (or saveplace) file.

Would it maybe make sense to introduce the possibility to create a
temporary, file-backed buffer, which does not trigger hooks exactly
like `with-temp-buffer' does, but provides the desired interactivity
with the user?  But maybe I am misinterpreting the usage of
`with-current-buffer' and it would be fine for `bookmark' and
`saveplace' to simply use `with-temp-buffer' in conjunction with
`insert-file-contents' to load data from disk.

Any thoughts on this?

-- Christoph



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-26  8:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26  8:42 Loading package data using with-current-buffer Christoph

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).