main
  1<!DOCTYPE html>
  2<html lang="en">
  3 <head>
  4  <meta name="viewport" content="width=device-width, initial-scale=1">
  5  <meta charset="utf-8">
  6  <meta name="viewport" content="width=device-width, initial-scale=1">
  7  <title>
  8   Emacs bankruptcy is fun
  9  </title>
 10  <meta name="author" content="Vincent Demeester">
 11  <meta name="generator" content="Org Mode">
 12  <meta name="viewport" content="width=device-width, initial-scale=1">
 13  <link href="/index.xml" rel="alternate" type="application/rss+xml" title="Vincent Demeester">
 14  <script src="/flux.js" defer=""></script>
 15  <link rel="stylesheet" href="/style.css" type="text/css">
 16 </head>
 17 <body>
 18  <div class="site-controls">
 19   <button class="theme-toggle" id="theme-toggle" title="Toggle dark/light mode">☀️</button>
 20  </div>
 21  <main id="content" class="content">
 22   <header>
 23    <h1 class="title">
 24     Emacs bankruptcy is fun
 25    </h1>
 26   </header>
 27   <section id="outline-container-introduction" class="outline-2">
 28    <h2 id="introduction">
 29     <a href="#introduction" class="anchor">§</a>Introduction
 30    </h2>
 31    <div id="text-introduction" class="outline-text-2">
 32     <p>
 33      Since go 1.14 go released, I’ve had a broken <code>go-mode</code> setup on my Emacs. I was using
 34<code>lsp-mode</code> and <code>gopls</code> and well, the update broke everything. I initally try to fix it but
 35I made it worse. At the same time, I started to get fed up with some performance issue of
 36my configuration and how slow my Emacs starts, about 6s.
 37     </p>
 38     <p>
 39      I, thus, declared my third Emacs bankruptcy, <code>:disabled</code> everything and slowly started
 40from scratch, with the following goal:
 41     </p>
 42     <ul class="org-ul">
 43      <li>
 44       Have it start quick, as less than a second, not too much more than <code>emacs -Q</code> would
 45      </li>
 46      <li>
 47       Disable anything that I don’t use often initially
 48      </li>
 49      <li>
 50       Try to use as much built-in as possible (example: using <code>icomplete</code> instead of
 51<code>ivy=/=counsel</code>)
 52      </li>
 53     </ul>
 54    </div>
 55   </section>
 56   <section id="outline-container-do-i-really-need-this-feature" class="outline-2">
 57    <h2 id="do-i-really-need-this-feature">
 58     <a href="#do-i-really-need-this-feature" class="anchor">§</a>Do I really need this feature
 59    </h2>
 60    <div id="text-do-i-really-need-this-feature" class="outline-text-2">
 61     <p>
 62      Following <a href="https://protesilaos.com/">Protesilaos Stavrou</a>’s emacs videos (and <a href="https://protesilaos.com/dotemacs/"><code>dotemacs</code></a>) for a while now, I have a
 63tendency to try to use built-in feature as much as possible. The most obvious example is
 64using <code>icomplete</code> instead of <code>ivy=/=counsel</code>.
 65     </p>
 66     <p>
 67      When I started my <i>bankruptcy</i>, I disabled every single customization I had, either using
 68<code>:disabled</code> when using <code>use-package</code> <b>or</b> the <code>(when nil)</code> <i>hack</i>. I then started Emacs
 69and acted on what was missing :
 70     </p>
 71     <ol class="org-ol">
 72      <li>
 73       Do I really miss it ? An example would be, at least initially, the completion in a <code>go</code>
 74file. I do miss it, but I miss it <b>way less</b> than having Emacs lagging because of
 75<code>lsp-mode</code> and showing me wrong completion.
 76      </li>
 77      <li>
 78       Is there a built-in option to what I previously used ? Here, the <code>icomplete</code> example
 79fits well, or <code>isearch</code> instead of <code>swiper</code>.
 80      </li>
 81      <li>
 82       Do I need it at startup or <i>on-demand</i> ?
 83      </li>
 84     </ol>
 85    </div>
 86   </section>
 87   <section id="outline-container-looking-into-what-takes-time" class="outline-2">
 88    <h2 id="looking-into-what-takes-time">
 89     <a href="#looking-into-what-takes-time" class="anchor">§</a>Looking into what takes time
 90    </h2>
 91    <div id="text-looking-into-what-takes-time" class="outline-text-2">
 92     <p>
 93      In “Advanced Techniques for Reducing Emacs Startup Time”<sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>, I discovered the <a href="https://github.com/jschaf/esup"><code>esup</code></a>
 94emacs library. In a gist, this is a profiler for Emacs. It starts a new Emacs instance and
 95look at the loading time.
 96     </p>
 97     <figure id="orgb8e5f7b">
 98      <img src="../images/2020-04-15-16-12-54.png" alt="2020-04-15-16-12-54.png">
 99      <figcaption>
100       <span class="figure-number">Figure 1: </span>esup “result” view
101      </figcaption>
102     </figure>
103     <p>
104      Then, you can do a simple loop:
105     </p>
106     <ul class="org-ul">
107      <li>
108       Run <code>esup</code>
109      </li>
110      <li>
111       Look at the top result
112      </li>
113      <li>
114       Fix it (lazy load, removing the feature, …)
115      </li>
116      <li>
117       Re-iterate
118      </li>
119     </ul>
120    </div>
121   </section>
122   <section id="outline-container-loading-on-demand" class="outline-2">
123    <h2 id="loading-on-demand">
124     <a href="#loading-on-demand" class="anchor">§</a>Loading on-demand
125    </h2>
126    <div id="text-loading-on-demand" class="outline-text-2">
127     <p>
128      Once you have the setup to know what takes time and what not, it’s time to look into how
129to load the most thing on demand.
130     </p>
131     <p>
132      For this, <a href="https://github.com/jwiegley/use-package"><code>use-package</code></a> is amazing, it tremendously help autoloading modules on-demand. If
133you are not using <code>use-package</code>, usually you are using <code>require</code>, which loads the
134underlying source file (all of it).
135     </p>
136     <p>
137      With <code>use-package</code>, there is multiple ways to load on demand:
138     </p>
139     <ul class="org-ul">
140      <li>
141       <code>:commands</code> to add callable that will trigger loading the package
142      </li>
143      <li>
144       <code>:bind</code>, <code>:bind*</code>, <code>:bind-keymap</code> and <code>:bind-keymap*</code> to bind key sequences to the
145global keymap or a specific keymap.
146      </li>
147      <li>
148       <code>:mode</code> and <code>:interpreter</code> establish a deferred binding with the <code>auto-mode-alist</code> and
149<code>interpreter-mode-alist</code>.
150      </li>
151      <li>
152       <code>:hook</code> allows adding functions onto the package hook
153      </li>
154      <li>
155       <code>:defer</code> is the most generic one, all the previous keyword imply <code>:defer</code>. You can
156specify a number of second of idle to load the package.
157      </li>
158     </ul>
159     <aside id="orgbb35d32">
160      <p>
161       In a gist for <code>org-babel</code>, use <code>use-package ob-python</code> and never call <code>org-babel-do-languages</code>.
162      </p>
163     </aside>
164     <p>
165      Once this is done, you are left with edge cases, like <code>org-babel-do-languages</code>.  Those are
166to be handle case by case. The good thing about those cases is that you’ll learn what
167those function do and this will give you an even better understanding of what is
168happening.
169     </p>
170     <p>
171      Doing this exercise also forces you to make you see if you really use that feature or
172not. I ended up removing entire feature from my configuration because they were taking
173quite some time to load, and was used almost never. Instead I am forcing myself to learn
174more what I can do with the built-in features first.
175     </p>
176    </div>
177   </section>
178   <section id="outline-container-conclusion" class="outline-2">
179    <h2 id="conclusion">
180     <a href="#conclusion" class="anchor">§</a>Conclusion
181    </h2>
182    <div id="text-conclusion" class="outline-text-2">
183     <p>
184      All in all, this <i>bankruptcy</i> was the most fun I had to do. I consider myself still in the
185process but the base is there.
186     </p>
187     <ol class="org-ol">
188      <li>
189       I learned a lot !
190      </li>
191      <li>
192       My Emacs starts in 0.6s against previously in 5s — <code>emacs -q</code> starts in about 0.3s so
193there is still a little bit of room for improvement.
194      </li>
195      <li>
196       I discovered / re-discovered a lot of built-in feature
197      </li>
198      <li>
199       I started documenting my configuration, see <a href="../configurations/emacs.html">here</a>.
200      </li>
201     </ol>
202     <p>
203      🎉
204     </p>
205     <div class="drawer update">
206      <h6>
207       Update
208      </h6>
209      <p>
210       Well, I’ve look into the <i>portable dump</i> feature of Emacs, thanks to <a href="https://archive.casouri.cat/note/2020/painless-transition-to-portable-dumper/index.html">Painless Transition
211to Portable Dumper</a>. And I am now down to <code>0.091s</code> for the startup. There is a few gotchas
212with <i>portable dump</i>, I’ll try to write about it later.
213      </p>
214     </div>
215    </div>
216   </section>
217   <div id="footnotes">
218    <h2 id="footnotes" class="footnotes">
219     <a href="#footnotes" class="anchor">§</a>Footnotes:
220    </h2>
221    <div id="text-footnotes">
222     <div class="footdef">
223      <sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup>
224      <div class="footpara" role="doc-footnote">
225       <p class="footpara">
226        : <a href="https://blog.d46.us/advanced-emacs-startup/">Advanced Techniques for Reducing Emacs Startup Time</a>
227       </p>
228      </div>
229     </div>
230    </div>
231   </div>
232  </main>
233  <footer id="postamble" class="status">
234   <footer>
235    <small><a href="/" rel="history">Index</a><a href="/sitemap.html">Sitemap</a><a href="https://dl.sbr.pm/">Files</a></small><br>
236     <small class="questions">Questions, comments ? Please use my <a href="https://lists.sr.ht/~vdemeester/public-inbox">public inbox</a> by sending a plain-text email to <a href="mailto:~vdemeester/public-inbox@lists.sr.ht">~vdemeester/public-inbox@lists.sr.ht</a>.</small><br>
237     <small class="copyright">
238      Content and design by Vincent Demeester
239      (<a rel="licence" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Some rights reserved</a>)
240    </small><br>
241   </footer>
242  </footer>
243 </body>
244</html>