rejeep / f.el

Modern API for working with files and directories in Emacs
GNU General Public License v3.0
680 stars 68 forks source link

Loading f-shortdoc slows down the loading process #113

Closed daanturo closed 1 year ago

daanturo commented 2 years ago

Contact Details

No response

Expected behavior

Loading f.el on Emacs 28+ shouldn't be slower than older versions

Actual behavior

Requiring the uncompiled "f-shortdoc" make loading "f.el" ~3 times slower.

Just using an newer version of Emacs makes startup a bit slower doesn't sound right.

f.el version

master

Emacs version

master

Relevant code or log output

With s, dash, shortdoc already loaded. f, f-short aren't.

(benchmark-progn (require 'f-shortdoc))
> Elapsed time: 0.001459s
(benchmark-progn (require 'f))
> Elapsed time: 0.000756s
Phundrak commented 2 years ago

I guess one of the reasons requiring `f-shortdoc' is it generates some results displayed in the shortdoc.

Is there any use case of f' where this difference is actually significant? Iff' takes only 2ms to load instead of 0.5ms, this shouldn’t be too much of an issue.

-- Lucien “Phundrak” Cartier-Tilet

https://phundrak.com (Français)

https://phundrak.com/en (English)

Sent from GNU/Emacs

daanturo commented 2 years ago

It's actually slower than reported than above, because f-shortdoc pulls shortdoc.el when f.el is loaded, especially the when not noninteractive.

With s, dash, already loaded. f, f-short, shortdoc aren't in an noninteractive session.

(benchmark-progn (require 'f-shortdoc))
> Elapsed time: 0.0040120s
(benchmark-progn (require 'f))
> Elapsed time: 0.000744s

Same conditions, interactive session:
Elapsed time: 0.043350s
Elapsed time: 0.010676s

shortdoc.el should only be loaded when shortdoc-display-group is called to avoid being loaded just for a rarely called command.

I think upstream should make define-short-documentation-group lazier. But currently IMO instead of this:

(when (version<= "28.1" emacs-version)
  (require 'f-shortdoc))

We should:

(eval-after-load 'shortdoc
  '(require 'f-shortdoc))

By trying this, I shaved the time taken to load f.el on my machine from ~0.055s to ~0.034s. Although the linter may complain about the usage of eval-after-load.