Apologies, the extreme slowdown for the regex in my setup is mostly credited to a very long line in my org file (~100k characters). I inserted a snippet from a log file to a quote block, without realizing that a large base64 string was hiding at the end of one line. The old regex could exclude that line early on, because it wasn't a header line, so I didn't notice a performance hit back then.

With that line deleted (org file shrinks to ~300KB), I measured performance with the new and old regex (new on 1st line vs old on 2nd line):

(elp-instrument-function 'org-font-lock-add-priority-faces)
(elp-reset-all)
;; open org file
(elp-results)


     Function Name                     Call Count  Elapsed Time Average Time
new: org-font-lock-add-priority-faces  28          0.0228787000 0.0008170964
old: org-font-lock-add-priority-faces  28          0.0007937999 2.834...e-05

So the new one is still considerably slower, but probably not noticeable unless the file is really large and/or it contains long lines.


One last remark, my workaround from the last mail is flawed, e.g. it broke priority sorting in my agendas. This one worked better:

(defun adv--org-font-lock-add-priority-faces (wrapped-func &rest args)
  (let ((org-priority-regexp "^\\*+ .*?\\(\\[#\\([A-Z0-9]+\\)\\] ?\\)"))
    (apply wrapped-func args)))
(advice-add 'org-font-lock-add-priority-faces :around #'adv--org-font-lock-add-priority-faces)


Reply via email to