URL:
  <https://savannah.gnu.org/patch/?10633>

                 Summary: Faster typing in long documents (incremental
typesetting caches)
                   Group: GNU TeXmacs
               Submitter: jacopo_rizzuto
               Submitted: Sat 26 Sep 2026 01:35:08 PM UTC
                Category: Typesetter
                  Action: None
                 Privacy: Public
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: trunk (SVN r15746) / GitHub development branch
           Fixed Release:
                  Stable:


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Sat 26 Sep 2026 01:35:08 PM UTC By: Jacopo_Rizzuto <jacopo_rizzuto>
In long documents (thousands of paragraphs), every keystroke costs 40-110 ms
of CPU, most of
all with the cursor near the start of the document, and TeXmacs falls behind
normal typing
(up to 2 s of lag). Although only the edited paragraph is retypeset, every
pass still walks
all paragraphs: it re-applies their environment changes, merges their lines
into the global
stack, rebuilds the merged stack boxes, repositions every box and, when the
document contains
floats, hands every line to the page breaker. After each pause in typing,
drd_update also
re-derives the properties of all macros of the style (~36 ms).

The attached series (10 commits, git format-patch; applies to trunk and to the
development
branch with "git am" or "patch -p1") adds exact caches for this work:

 1. box_rep::redraw: linear instead of quadratic accumulation of rectangles
 2. composite_box_rep::finalize: compare inverse paths without reversed
copies
 3. stack/phrase boxes: skip position_at for boxes that did not move
 4. merge_stack: memoize the shove between successive paragraphs
 5. bridge_rep::typeset: keep the merged stack item of unchanged paragraphs
 6. bridge_document: replay blocks of unchanged paragraphs in one step
 7. with floats: merge runs of ordinary lines into cached chunks for the
pager
 8. typeset_prepare: cache the default environment patched with the preamble
 9. drd_update: skip heuristic_init when neither drd nor environment changed
10. Scheme: cheaper tm-func? and title/abstract proposal predicates

CPU per key, same keys sent to both builds every 60 ms (continuous page
mode):
  synthetic, 2,000 paragraphs:                 57.4 -> 24.7 ms
  synthetic, 3,500 paragraphs with floats:     61.7 -> 30.9 ms
  same, typing with Return:                    83.3 -> 36.2 ms
  real lecture notes (TeXmacs 2.1.4):          58.6 -> 30.9 ms, 80.5 -> 47.3
ms
Paper page mode: unchanged (63.0 vs 62.4 ms).

Testing: identical paragraph geometry and byte-identical screenshots (325
pages, five
documents, continuous and paper mode) after a fixed edit sequence (typing,
Return, new
section, math, Backspace, joining paragraphs, undo); identical (run-all-tests)
output;
each commit builds on its own (trunk, CMake, Qt5, embedded Guile 1.8).

Risks: every cache is only correct if its validity check sees every relevant
change. The
most delicate one is the block replay (6), which applies the environment
changes of a block
of paragraphs as one composed patch (as the unpatched code already does within
each
paragraph). Other possible failures: stale screen areas if a box were modified
in place
after construction (3), stale macro properties if a drd were changed without
its setters (9).
Not tested: multi-column documents, other styles and plugins, macOS/Windows,
repaints
interrupted by input. The pull request description explains every commit in
detail (why,
how, why it is safe, what could break).

Before/after videos, measurements, test documents and a full report:
  https://github.com/GliAcopo/texmacs-typing-performance
The same series as a GitHub pull request (against development):
  https://github.com/texmacs/texmacs/pull/112

This work was done with the help of Claude Opus 5.5.







    _______________________________________________________
File Attachments:

Name: texmacs-faster-typing-series.patch Size: 51KiB

<https://file.savannah.gnu.org/file/texmacs-faster-typing-series.patch?file_id=59027>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-493d9aabe13fbadf30bb331d4280224ebc5f2d12.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/patch/?10633>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Texmacs-patch mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/texmacs-patch

Reply via email to