Here is a patch which solves the problem by eagerly loading the
appropriate stuff.

>From 661176eb8b089e7716218a05b00ac110aefddde4 Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email protected]>
Date: Tue, 22 Sep 2026 15:50:04 -0400
Subject: [PATCH] mk/org-fixup.el: Speed up loaddefs generation

This speeds up loaddefs generation from 1.905 to 1.059 seconds for me
on Emacs 32.0.50.
* mk/org-fixup.el (org-make-org-loaddefs) Speed up loaddefs generation
by eagerly loading macros.
---
 mk/org-fixup.el | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mk/org-fixup.el b/mk/org-fixup.el
index 8a97abb52..3bbbca249 100644
--- a/mk/org-fixup.el
+++ b/mk/org-fixup.el
@@ -92,6 +92,14 @@ org-make-org-loaddefs
 be used by foreign build systems or installers to produce this
 file in the installation directory of Org mode.  Org will not
 work correctly if this file is not up-to-date."
+  ;; Speed up the generation of loaddefs by loading relevant macros.
+  ;; Emacs >= 31 will use information from macros in the autoloads
+  ;; generation.  If the macro isn't loaded, then the entire file will
+  ;; be loaded to try and load that macro.
+  ;; So if you see an output line like this:
+  ;;    loaddefs-gen: loading file org-element (for cl-defun)
+  ;; then add the appropriate require here to avoid that.
+  (require 'cl-macs)
   (let ((outfile "org-loaddefs.el"))
     (if (fboundp 'loaddefs-generate)    ; FIXME: Emacs >= 29
         (loaddefs-generate default-directory (expand-file-name outfile))
-- 
2.54.0

Reply via email to