Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow straight bootstrap #726

Closed
haji-ali opened this issue Mar 24, 2021 · 5 comments
Closed

Slow straight bootstrap #726

haji-ali opened this issue Mar 24, 2021 · 5 comments
Labels

Comments

@haji-ali
Copy link

How long is bootstrapping straight expected to take?
Right now it is taking an average of 1.7 seconds on my machine (compared to the rest of my config which takes less than 0.5 seconds). I benchmarked bootstrap.el and it seems that executing these lines

https://github.com/raxod502/straight.el/blob/e1390a933b6f5a15079d6dec91eac97a17aad10c/bootstrap.el#L82-L84

Takes an average of 1.6 seconds.

Is this expected? If so, is there a way to speed this up?

@progfolio
Copy link
Contributor

Does the bootstrap process take that long when using straight-bug-report?

@haji-ali
Copy link
Author

haji-ali commented Mar 24, 2021

No, it seems to run much faster. Running

(straight-bug-report
  :pre-bootstrap
  (setq my//bootstrap-start (current-time))
  :post-bootstrap
  (message "Bootstrapping done in %.03fs"
           (float-time (time-subtract (current-time) my//bootstrap-start)))
  :user-dir "/tmp/straight.el-test"
  :preserve t)

the second time takes 0.1 to 0.2 seconds.

This might be a bug in Radian then. Is there a more verbose mode of straight that I can enable to get diagnostics of what straight is doing?

@progfolio
Copy link
Contributor

progfolio commented Mar 24, 2021

Is there a more verbose mode of straight that I can enable to get diagnostics of what straight is doing?

In this situation I would recommend using Emac's elisp profiler:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html

You could advise straight-use-recipes and conditionally start/stop the profiler when
the package is melpa. Try adding something like this prior to straight's bootstrap code (I'm not familiar enough with Radian to say exactly where):

(defun +straight-profile-use-recipes (advised recipe)
  (let ((melpa (eq (car recipe) 'melpa)))
    (when melpa (profiler-start 'cpu+mem))
    (prog1
        (funcall advised recipe)
      (when melpa (profiler-stop)))))

(advice-add #'straight-use-recipes :around #'+straight-profile-use-recipes)

This will add the advice and start the profiler when the melpa recipe is passed to straight-use-recipes.

Then after init, you can M-x profiler-report. This will pop open the profiler buffer. You should be able to see where most of the CPU time is being spent there by drilling down through the report. If nothing looks amiss, you may have to move the call to profiler-start sooner. In that case I would ditch the advice and just insert the calls into your init file.

Does that help?

@haji-ali
Copy link
Author

haji-ali commented Mar 24, 2021

Thank you! This is a really nice way to profile.

I found out that the reason is that straight--cache-package-modifications is being called at start-up which is really slow.
This is because straight-check-for-modifications has find-at-startup by default and I have many files in my straight repo directory. Removing this flag improved my Emacs startup time considerably.

@raxod502
Copy link
Member

Right, see https://github.com/raxod502/straight.el/tree/e1390a933b6f5a15079d6dec91eac97a17aad10c#summary-of-options-for-package-modification-detection. There are tradeoffs between startup time, reliability of modification detection, and number of system dependencies for the different strategies for modification detection.

See also #694 (comment), in @progfolio came up with an idea that might be able to get all the advantages without any real downsides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants