From: Kyle Meyer <firstname.lastname@example.org> To: Emily Bourke <email@example.com> Cc: "firstname.lastname@example.org" <email@example.com> Subject: Re: [PATCH] ox-publish.el: Speed up org-publish-cache-file-needs-publishing Date: Mon, 04 Jan 2021 03:28:19 GMT [thread overview] Message-ID: <firstname.lastname@example.org> (raw) In-Reply-To: <OfdVIrkD5F624hYL-8RdJ5OLPKgi9CuuAwn8d6wPv2QS52VQAyvh9jSagdldoir66UVdEM1v_4oBR01jbvMC7HbvnECUEl4ShY4XplndClYemail@example.com> Thank you for the patch. Emily Bourke writes: > 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? Nothing jumps out to me. For large files that are already visited, I suppose find-file-noselect returning an existing buffer can be faster, so relevant factors would include how many Org files a project has, how large they are, and how many of those are visited in the current session. My guess is that using with-temp-buffer and insert-file-contents would be a net gain, though that gain would be narrowed some if the temporary buffer was put into org-mode rather than kept in fundamental-mode (more below). > 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. This reads to me like after-find-file is the hook itself. Perhaps something like this would be clearer: "... avoids calling after-find-file and running find-file-hook, ...". > 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)) The goto-char call can be dropped now because insert-file-contents inserts after point. Unlike the previous code, this doesn't activate org-mode in the buffer. That gives a speedup. And I don't spot any code downstream that depends on the major mode being org-mode, so it's probably safe, though perhaps there's a subtle change in behavior here (e.g., related to syntax table). If org-mode isn't called, the org-inhibit-startup binding above could be dropped. > + (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)) This introduces a regression. With the previous code, the find-file-noselect call led to default-directory being set to the Org file's directory, and then this expand-file call on the included file was relative to that. With the new code, default-directory isn't changed, so it points to a non-existing or incorrect file unless the current default-directory and the Org file's happen to match. > + included-files-ctime)))))))))
next prev parent reply other threads:[~2021-01-04 3:29 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-01 19:58 Emily Bourke 2021-01-04 3:28 ` Kyle Meyer [this message] 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] ` <firstname.lastname@example.org> [not found] ` <A2476131-8275-48D6-AF10-902CF347C1F9@whil.se> [not found] ` <email@example.com> 2021-10-03 1:50 ` Fwd: " Gustav Wikström 2021-01-07 1:11 ` Dr. Arne Babenhauserheide
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH] ox-publish.el: Speed up org-publish-cache-file-needs-publishing' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this 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).