emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loading package data using with-current-buffer


From: Christoph
Subject: Loading package data using with-current-buffer
Date: Sat, 26 Aug 2023 10:42:26 +0200

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]