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))
c
(puthash seq
(let ((seq (if (listp seq) seq (list seq))))
(cond ((stringp (car seq))
(cl-find-if
(lambda (str)
(and (mapcar #'char-displayable-p (string-to-list str))))
seq))
((characterp (car seq))
(cl-find-if #'char-displayable-p seq))))
markdown--first-displayable-cache))))