[CM] TeXmacs & S7

Massimiliano Gubinelli m.gubinelli at gmail.com
Mon Jan 17 10:41:57 PST 2022


Dear all,

 integration of S7 in the TeXmacs document editor (www.texmacs.org) has been quite successful so far. You can grab the associated development branch here at github

https://github.com/texmacs/texmacs/tree/wip_s7

you will need Qt 4/5 and some other libraries to compile it. Some preliminary tests (which I think I've already posted on this list) and comments on the intergation of various kinds of schemes in TeXmacs are here

https://texmacs.github.io/notes/docs/scheming.html

Speed is great, much better than guile 1.8 (our standard scheme implementation) for the most part. Some users reported slowing down in some tasks (like converting to LaTeX) but I still haven't measured this.

We use a mostly unmodified version of S7 where only the patch attached below is used. It modifies the way lookup_from works, by putting at the beginning of the symbol list symbols which are way back and are looked upon. For us this is a game-changer : without it TeXmacs/S7 is unusable. We rely on scheme on many places, in particular the menus and the UI is dynamically generated from scheme descriptions at each keypress, in response to changes of the position of the cursor in the document (which affects which element the user is current focussing and therefore which UI elements are appropriate to show). 

We experience problems with the memory footprint of the program. TeXmacs/Guile uses usually ~500MB on my Mac while TeXmacs/S7 goes slowly up to ~1GB and some users saw also ~2GB of memory footprint. 

I have a couple of requests for the developer(s?):

1) would it be possible to have loopup_from implemented via some hash table or some speedier lookup? It would be great to shave some more performances out of this. Alternatively, can our patch be made into the official version? (or maybe some improved version of it)

2) Suggestions to explain the high memory usage? Do somebody else also experience these problems?

Thanks for this great program.

Best regards,
Massimiliano Gubinelli 


------

diff --git a/src/src/Scheme/S7/s7.c b/src/src/Scheme/S7/s7.c
index ed5965591..f0c3488dd 100644
--- a/src/src/Scheme/S7/s7.c
+++ b/src/src/Scheme/S7/s7.c
@@ -10124,10 +10124,20 @@ static inline s7_pointer lookup_from(s7_scheme *sc, const s7_pointer symbol, s7_
     }
   for (; is_let(e); e = let_outlet(e))
     {
-      s7_pointer y;
-      for (y = let_slots(e); tis_slot(y); y = next_slot(y))
-       if (slot_symbol(y) == symbol)
-         return(slot_value(y));
+      s7_pointer y, py;
+      int steps = 0;
+      for (y = let_slots(e); tis_slot(y); py = y, y = next_slot(y), steps++)
+  if (slot_symbol(y) == symbol) {
+    /* (TeXmacs) We try to bring back symbols which are used frequently to the
+       beginning of the list. This improves the lookup in TeXmacs.
+       The threshold is chosen heuristically.*/
+    if (steps > 100) {
+       next_slot(py) = next_slot(y);
+       next_slot(y) = let_slots(e);
+       let_slots(e) = y;
+    }
+    return(slot_value(y));
+  }
     }
   if (is_slot(global_slot(symbol)))
     return(slot_value(global_slot(symbol)));




More information about the Cmdist mailing list