* ORG: I dont like org-link-make-regexps that create regex for this search, it
is very complex and very hard for customization.
---
* ORG: In (org-activate-links)
1. ~(buffer-substring-no-properties start end)~ - may be replaced to code that
instead of copying string check text directly in buffer:
```elisp
(not (save-excursion
(goto-char start)
(re-search-forward org-element-paragraph-separate end t)))
```
2. Calling org-link-get-parameter repeatedly for the same type does redundant
alist/plist lookups on every link. Also, :help-echo passes through both strings
and functions without invoking functions—which is intentional for Emacs
help-echo, though easy to misread as a missing (funcall ...).
Possible way to fix: Fetch the link parameter plist once (e.g., params or a
small helper/local bindings) for type instead of scanning/looking up parameters
repeatedly on every link.
---
* For **font-lock-fontify-keywords-region**:
1. Redundant (save-excursion (goto-char (match-beginning 0)) (forward-line 1)
(point))
Possible ways to fix:
- Compute the line-end position once per match and bind it to a local
variable (e.g., eol-after-match), reusing it across the when check and
put-text-property (text properties dont add text to a buffer).
- Or, guard save-excursion behind a cheap
check first (such as ~(and font-lock-multiline (> (point) (match-beginning
0))))~.
2. Unnecessary font-lock-multiline Work When font-lock-multiline Is nil
: font-lock-multiline ((save-excursion ... (forward-line 1) (point)))
Calling save-excursion + forward-line three times per match when
font-lock-multiline is enabled is wasteful.
Markers in Emacs are tracked in
buffer marker lists, so unused markers add unnecessary allocation and
GC/list overhead.
Possible ways to fix:
- Computing that boundary once per match when (and font-lock-multiline (>
(point) (match-beginning 0))) is true avoids extra buffer motion.
- avoid creating markers ((make-marker)) eagerly if anchored keywords aren't
even used, or keep marker allocation lazy until the first anchored keyword is
encountered.
3. (incf count): incf is a cl-lib macro;
In hot loops or status reporting, ~(setq count (1+ count))~ is idiomatic
built-in Elisp (and loudly is usually nil during normal editing, though
message + make-string is expensive whenever loudly is truthy).
---
Derek Chen-Becker <[email protected]> writes:
> Confirmed, for Emacs 31.1 using Org 9.8.7 (bundled with Emacs).
>
> I ran the profiler (profiler-start, <do a bunch of typing in a large
> block>, profiler-report, profiler-stop) and it looks like a fair amount of
> work going into font lock, which I guess makes sense from the standpoint of
> working over a large block of text. I'm not familiar enough with this to
> say where there might be efficiency gains or if there's a bug here that's
> making it slower.
>
> Cheers,
>
> Derek
>
> 4307 65% - redisplay_internal (C function)
> 3190 48% - jit-lock-function
> 3190 48% - jit-lock-fontify-now
> 3157 48% - jit-lock--run-functions
> 3157 48% - #<byte-code-function C77>
> 3157 48% - font-lock-fontify-region
> 3157 48% - font-lock-default-fontify-region
> 3050 46% - font-lock-fontify-keywords-region
> 761 11% - org-activate-links
> 761 11% re-search-forward
> 660 10% - org-activate-folds
> 547 8% - org-fold-core-get-folding-spec
> 165 2% get-char-property
> 106 1% buffer-local-value
> 98 1% + org-fold-core--property-symbol-get-create
> 8 0% reverse
> 4 0% org-element-type
> 66 1% search-forward
> 248 3% + org-fontify-meta-lines-and-blocks
> 228 3% + org-do-emphasis-faces
> 192 2% + org-fontify-inline-src-blocks
> 53 0% + org-fontify-macros
> 53 0% + org-fontify-drawers
> 36 0% org-cite-activate
> 31 0% + org-activate-code
> 25 0% + org-activate-dates
> 19 0% + org-font-lock-add-priority-faces
> 19 0% + org-activate-tags
> 15 0% + org-activate-footnote-links
> 4 0% org-font-lock-add-tag-faces
> 4 0% eval
> 96 1% + font-lock-unfontify-region
> 11 0% font-lock-extend-region-multiline
> 28 0% put-text-property
> 14 0% file-remote-p
> 6 0% + eval
> 1955 29% Automatic GC
> 216 3% + command-execute
> 93 1% + timer-event-handler
> 0 0% ...
>
>
>
> On Tue, Nov 3, 2026 at 5:55 PM Anoncheg <[email protected]> wrote:
>
>> Hi, I have custom block in test.org file:
>>
>> #+begin_cui
>> Much of text here (2319 lines, 573 sentences, 15713 words, and 112229
>> characters)
>> ...
>> #+end_cui
>>
>> I open file this way: `emacs --no-site-file -Q test.org`.
>>
>> When I type characters anywhere near or inside this block, I experience
>> some delay and
>> high CPU load. If there isn’t much text inside the block, there are no
>> freezes. The same issue
>> occurs when I enable support for this block in Org-mode as follows:
>> ```
>> (add-to-list 'org-protecting-blocks "cui")
>> (add-to-list 'org-babel-tangle-lang-exts '("cui" . "cui"))
>> ```
>>
>> `(print system-configuration-options)` :
>> ```n
>> "--prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
>> --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share
>> --sysconfdir=/etc --localstatedir=/var/lib --datarootdir=/usr/share
>> --disable-silent-rules --docdir=/usr/share/doc/emacs-31.1-r2
>> --htmldir=/usr/share/doc/emacs-31.1-r2/html --libdir=/usr/lib64
>> --program-suffix=-emacs-31 --includedir=/usr/include/emacs-31
>> --infodir=/usr/share/info/emacs-31 --localstatedir=/var
>> --enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
>> --without-compress-install --without-pop --without-systemduserunitdir
>> --with-file-notification=inotify --with-pdumper --enable-acl --enable-xattr
>> --without-dbus --without-modules --without-gameuser --with-libgmp
>> --without-gpm --without-native-compilation --without-lcms2 --with-xml2
>> --without-mailutils --without-selinux --without-sqlite3 --with-gnutls
>> --without-libsystemd --with-threads --with-tree-sitter --without-wide-int
>> --with-sound=no --with-zlib --with-pgtk --without-x --without-ns
>> --with-toolkit-scroll-bars --without-gconf --without-gsettings
>> --without-harfbuzz --without-libotf --without-m17n-flt --without-xwidgets
>> --with-gif --with-jpeg --with-png --with-rsvg --without-tiff --with-webp
>> --without-imagemagick --with-dumping=pdumper 'CFLAGS=-O2 -march=raptorlake
>> -pipe -fno-fast-math -ffp-contract=off' 'CPPFLAGS= -DUSE_VALGRIND=no'
>> 'LDFLAGS=-Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs'" [2 times]
>> ```
>>
>> Please help find the reason for the high CPU load.
>> --
>> Best regards,
>> Python+Java+Bash+Lisp Data Scientist, AI Engineer without a job for 4
>> years.
>> PGP pub key: DB8A27FEDA7B4545603396FFC81251BC87659B81
>>
>>
>
> --
> +---------------------------------------------------------------+
> | Derek Chen-Becker |
> | GPG Key available at https://keybase.io/dchenbecker and |
> | https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org |
> | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7 7F42 AFC5 AFEE 96E4 6ACC |
> +---------------------------------------------------------------+
> Confirmed, for Emacs 31.1 using Org 9.8.7 (bundled with Emacs).
>
> I ran the profiler (profiler-start, <do a bunch of typing in a large block>,
> profiler-report, profiler-stop) and it looks like a fair amount of
> work going into font lock, which I guess makes sense from the standpoint of
> working over a large block of text. I'm not familiar enough
> with this to say where there might be efficiency gains or if there's a bug
> here that's making it slower.
>
> Cheers,
>
> Derek
>
> 4307 65% - redisplay_internal (C function)
> 3190 48% - jit-lock-function
> 3190 48% - jit-lock-fontify-now
> 3157 48% - jit-lock--run-functions
> 3157 48% - #<byte-code-function C77>
> 3157 48% - font-lock-fontify-region
> 3157 48% - font-lock-default-fontify-region
> 3050 46% - font-lock-fontify-keywords-region
> 761 11% - org-activate-links
> 761 11% re-search-forward
> 660 10% - org-activate-folds
> 547 8% - org-fold-core-get-folding-spec
> 165 2% get-char-property
> 106 1% buffer-local-value
> 98 1% + org-fold-core--property-symbol-get-create
> 8 0% reverse
> 4 0% org-element-type
> 66 1% search-forward
> 248 3% + org-fontify-meta-lines-and-blocks
> 228 3% + org-do-emphasis-faces
> 192 2% + org-fontify-inline-src-blocks
> 53 0% + org-fontify-macros
> 53 0% + org-fontify-drawers
> 36 0% org-cite-activate
> 31 0% + org-activate-code
> 25 0% + org-activate-dates
> 19 0% + org-font-lock-add-priority-faces
> 19 0% + org-activate-tags
> 15 0% + org-activate-footnote-links
> 4 0% org-font-lock-add-tag-faces
> 4 0% eval
> 96 1% + font-lock-unfontify-region
> 11 0% font-lock-extend-region-multiline
> 28 0% put-text-property
> 14 0% file-remote-p
> 6 0% + eval
> 1955 29% Automatic GC
> 216 3% + command-execute
> 93 1% + timer-event-handler
> 0 0% ...
>
> On Tue, Nov 3, 2026 at 5:55 PM Anoncheg <[email protected]> wrote:
>
> Hi, I have custom block in test.org file:
>
> #+begin_cui
> Much of text here (2319 lines, 573 sentences, 15713 words, and 112229
> characters)
> ...
> #+end_cui
>
> I open file this way: `emacs --no-site-file -Q test.org`.
>
> When I type characters anywhere near or inside this block, I experience some
> delay and
> high CPU load. If there isn’t much text inside the block, there are no
> freezes. The same issue
> occurs when I enable support for this block in Org-mode as follows:
> ```
> (add-to-list 'org-protecting-blocks "cui")
> (add-to-list 'org-babel-tangle-lang-exts '("cui" . "cui"))
> ```
>
> `(print system-configuration-options)` :
> ```n
> "--prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
> --mandir=/usr/share/man --infodir=/usr/share/info -
> -datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib
> --datarootdir=/usr/share --disable-silent-rules -
> -docdir=/usr/share/doc/emacs-31.1-r2
> --htmldir=/usr/share/doc/emacs-31.1-r2/html --libdir=/usr/lib64
> --program-suffix=-emacs-31
> --includedir=/usr/include/emacs-31 --infodir=/usr/share/info/emacs-31
> --localstatedir=/var -
> -enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
> --without-compress-install --without-pop --without-systemduserunitdir -
> -with-file-notification=inotify --with-pdumper --enable-acl --enable-xattr
> --without-dbus --without-modules --without-gameuser -
> -with-libgmp --without-gpm --without-native-compilation --without-lcms2
> --with-xml2 --without-mailutils --without-selinux -
> -without-sqlite3 --with-gnutls --without-libsystemd --with-threads
> --with-tree-sitter --without-wide-int --with-sound=no --with-zlib -
> -with-pgtk --without-x --without-ns --with-toolkit-scroll-bars
> --without-gconf --without-gsettings --without-harfbuzz --without-libotf -
> -without-m17n-flt --without-xwidgets --with-gif --with-jpeg --with-png
> --with-rsvg --without-tiff --with-webp --without-imagemagick -
> -with-dumping=pdumper 'CFLAGS=-O2 -march=raptorlake -pipe -fno-fast-math
> -ffp-contract=off' 'CPPFLAGS= -
> DUSE_VALGRIND=no' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed
> -Wl,-z,pack-relative-relocs'" [2 times]
> ```
>
> Please help find the reason for the high CPU load.
> --
> Best regards,
> Python+Java+Bash+Lisp Data Scientist, AI Engineer without a job for 4 years.
> PGP pub key: DB8A27FEDA7B4545603396FFC81251BC87659B81
>
> --
> +---------------------------------------------------------------+
> | Derek Chen-Becker |
> | GPG Key available at https://keybase.io/dchenbecker and |
> | https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org |
> | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7 7F42 AFC5 AFEE 96E4 6ACC |
> +---------------------------------------------------------------+
--
Best regards,
Python+Java+Bash+Lisp Data Scientist, AI Engineer
PGP pub key: DB8A27FEDA7B4545603396FFC81251BC87659B81
*