I come back to emacs after an eternity without using it. I used it before but now that I'm a grown up I'd like to understand what I do and how to do stuff.

I use emacs mainly for markdown edit at the moment. I have absolutely no problem with the markdown mode I use... until I create a link [foo](url). After that emacs becomes so slow that it's almost impossible to use. I think it may come from my .emacs configuration but I don't know what to do there. I tried to change the markdown mode I used and the result is the same (switching from poly-markdown to markdown-mode+).

Could please help me to learn how to investigate and (if possible) solve that kind of issue when it happens?

## Edit:

Thanks to @Stefan I learnt how to run the profiler and check what's taking all the resources. Obviously it's somehow due to markdown--first-displayable ... char-displayable-p. What can I do now? What are the options?

- ...                                                            1294  99%
 - jit-lock-fontify-now                                          1256  96%
  - jit-lock--run-functions                                      1256  96%
   - run-hook-wrapped                                            1256  96%
    - #<compiled 0x294f1c9>                                      1256  96%
     - font-lock-fontify-region                                  1256  96%
      - font-lock-default-fontify-region                         1256  96%
       - font-lock-fontify-keywords-region                       1256  96%
        - markdown-fontify-inline-links                          1256  96%
         - markdown--first-displayable                           1256  96%
          - cl-find-if                                           1256  96%
           - apply                                               1256  96%
            - cl-find                                            1256  96%
             - apply                                             1256  96%
              - cl-position                                      1256  96%
               - cl--position                                    1256  96%
                - char-displayable-p                             1256  96%
  • 2
    You might want to rephrase your question to clarify what it is you want: one part is basically a kind of bug report about links being slow in the markdown mode you use, the other part is asking how to debug performance problems (and this is independent from markdown-mode).
    – Stefan
    Nov 20, 2018 at 17:17
  • This question is now useless since the pastebin has been removed—it is impossible to follow either the question or the accepted answer. But, the accepted answer does have useful information, so I’m not suggesting this question be removed—yet. lvictorino, could you please restore a permalink to the version of your .emacs that caused the issue, or edit the question to include the relevant snippet of Elisp code?
    – Trey
    Feb 17, 2020 at 22:16

1 Answer 1


To debug performance problems, one approach is to use the built-in profiler:

M-x profiler-start RET RET
<reproduce the slowdown, ideally for a good 10s or so>
M-x profiler-report RET

Then browse the report (C-u RET is an important command there) to see where all that time is spent.

Seeing your profiler report, you'll probably want to file a bug report with the markdown-mode maintainer to see how to change the code of markdown-fontify-inline-links to try and make it faster.

In the mean time you can try a quick memoizing hack:

(defvar markdown--first-displayable-cache (make-hash-table :test #'equal))

(defun markdown--first-displayable (seq)
  "Return the first displayable character or string in SEQ.
SEQ may be an atom or a sequence."
  (let ((c (gethash seq markdown--first-displayable-cache t)))
    (if (not (eq c t))
      (puthash seq
               (let ((seq (if (listp seq) seq (list seq))))
                 (cond ((stringp (car seq))
                         (lambda (str)
                           (and (mapcar #'char-displayable-p (string-to-list str))))
                       ((characterp (car seq))
                        (cl-find-if #'char-displayable-p seq))))
  • Awesome thanks! I'll update my post with the result.
    – lvictorino
    Nov 20, 2018 at 18:03
  • Whoa. Ok. Ok. Your edit works... but what does it do? (thanks a lot for your time and help).
    – lvictorino
    Nov 20, 2018 at 20:04
  • 1
    @Ivictorino: it's called memoization
    – Stefan
    Nov 20, 2018 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.