emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-publish.el: Speed up org-publish-cache-file-needs-publishing
@ 2021-01-01 19:58 Emily Bourke
  2021-01-04  3:28 ` Kyle Meyer
  0 siblings, 1 reply; 14+ messages in thread
From: Emily Bourke @ 2021-01-01 19:58 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

Hi,

I found publishing when there were no changes to be slower than expected. Profiling showed me that `org-publish-cache-file-needs-publishing' was invoking the `after-find-file' hooks, which I don't think is necessary.

I've changed it to avoid doing that, by using `with-temp-buffer' and `insert-file-contents', and noticed a significant increase in speed.

Is there any reason I'm missing for using `find-file-noselect' in this case?

Best wishes,
Emily Bourke

[-- Attachment #2: 0001-ox-publish.el-Speed-up-org-publish-cache-file-needs-.patch --]
[-- Type: application/octet-stream, Size: 2742 bytes --]

From 0ae9d031ec368ddfe6295dce76aafbd368c5eb25 Mon Sep 17 00:00:00 2001
From: Emily Bourke <undergroundquizscene@gmail.com>
Date: Fri, 1 Jan 2021 18:47:45 +0000
Subject: [PATCH] ox-publish.el: Speed up
 org-publish-cache-file-needs-publishing

* lisp/ox-publish.el (org-publish-cache-file-needs-publishing): Use
`with-temp-buffer' with `insert-file-contents' instead of
`find-file-noselect'.  This avoids running the `after-find-file' hook,
which can make it significantly faster.

TINYCHANGE
---
 lisp/ox-publish.el | 43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 7bb2fed6e..e967286cf 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -1290,29 +1290,26 @@ the file including them will be republished as well."
 	 (org-inhibit-startup t)
 	 included-files-ctime)
     (when (equal (file-name-extension filename) "org")
-      (let ((visiting (find-buffer-visiting filename))
-	    (buf (find-file-noselect filename))
-	    (case-fold-search t))
-	(unwind-protect
-	    (with-current-buffer buf
-	      (goto-char (point-min))
-	      (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
-		(let ((element (org-element-at-point)))
-		  (when (eq 'keyword (org-element-type element))
-		    (let* ((value (org-element-property :value element))
-			   (filename
-			    (and (string-match "\\`\\(\".+?\"\\|\\S-+\\)" value)
-				 (let ((m (org-strip-quotes
-					   (match-string 1 value))))
-				   ;; Ignore search suffix.
-				   (if (string-match "::.*?\\'" m)
-				       (substring m 0 (match-beginning 0))
-				     m)))))
-		      (when filename
-			(push (org-publish-cache-ctime-of-src
-			       (expand-file-name filename))
-			      included-files-ctime)))))))
-	  (unless visiting (kill-buffer buf)))))
+      (let ((case-fold-search t))
+	(with-temp-buffer
+	  (insert-file-contents filename)
+	  (goto-char (point-min))
+	  (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t)
+	    (let ((element (org-element-at-point)))
+	      (when (eq 'keyword (org-element-type element))
+		(let* ((value (org-element-property :value element))
+		       (filename
+			(and (string-match "\\`\\(\".+?\"\\|\\S-+\\)" value)
+			     (let ((m (org-strip-quotes
+				       (match-string 1 value))))
+			       ;; Ignore search suffix.
+			       (if (string-match "::.*?\\'" m)
+				   (substring m 0 (match-beginning 0))
+				 m)))))
+		  (when filename
+		    (push (org-publish-cache-ctime-of-src
+			   (expand-file-name filename))
+			  included-files-ctime)))))))))
     (or (null pstamp)
 	(let ((ctime (org-publish-cache-ctime-of-src filename)))
 	  (or (time-less-p pstamp ctime)
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-10-03  2:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-01 19:58 [PATCH] ox-publish.el: Speed up org-publish-cache-file-needs-publishing Emily Bourke
2021-01-04  3:28 ` Kyle Meyer
2021-01-06 20:58   ` Emily Bourke
2021-05-01 10:22     ` Bastien
2021-05-05 18:55       ` Emily Bourke
2021-09-26 10:26         ` Bastien
2021-09-26 11:58           ` Emily Bourke
2021-09-26 13:22             ` Bastien
2021-09-26 15:14               ` Emily Bourke
2021-09-27  8:33                 ` Emily Bourke
2021-09-27  8:48                   ` Bastien
2021-09-27  8:50                     ` Emily Bourke
     [not found]                     ` <DB6PR02MB3174059E6DD21014657284A0DAA79@DB6PR02MB3174.eurprd02.prod.outlook.com>
     [not found]                       ` <87czotpyk0.fsf@bzg.fr>
     [not found]                         ` <A2476131-8275-48D6-AF10-902CF347C1F9@whil.se>
     [not found]                           ` <874ka5pwxo.fsf@gnu.org>
2021-10-03  1:50                             ` Fwd: " Gustav Wikström
2021-01-07  1:11   ` Dr. Arne Babenhauserheide

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).