From 7a4925cac6c307eab955dd0d67ab95a8fdb72ebd Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 3 Jan 2023 16:46:35 +0800 Subject: [PATCH] org-latex-preview: Reduce overhead in SVG editing * lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor): By setting the coding system and avoiding triggering any file handlers (such as the `image-file-handler'), memory usage is nearly halved, reducing GC pressure. --- lisp/org-latex-preview.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 7496ff1de..0d5f3f853 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -1189,7 +1189,14 @@ EXTENDED-INFO, and displayed in the buffer." The foreground color is guessed to be the first specified fill color, which appears to be a reliable heuristic from a few tests with the output of dvisvgm." - (let ((write-region-inhibit-fsync t)) + (let ((write-region-inhibit-fsync t) + ;; dvisvgm produces UTF-8 encoded files, so we might as well + ;; avoid calling `find-auto-coding'. + (coding-system-for-read 'utf-8) + (coding-system-for-write 'utf-8) + ;; Prevent any file handlers (specifically + ;; `image-file-handler') from being called. + (file-name-handler-alist nil)) (with-temp-buffer (insert-file-contents (plist-get svg-fragment :path)) (goto-char (point-min))