Performance optimization for gopher and finger xfers.
authorTim Vaughan <timv@ughan.xyz>
Fri, 15 May 2020 17:12:32 +0000 (19:12 +0200)
committerTim Vaughan <timv@ughan.xyz>
Fri, 15 May 2020 17:14:43 +0000 (19:14 +0200)
ISSUES.org
elpher.el

index 5f45081..03ca588 100644 (file)
@@ -43,9 +43,17 @@ gopher "getter" code differently.
 
 
 ** OPEN Add history browsing
+   
+** OPEN Download/rendering progress feedback
+   Particularly for large files or complicated pages, elpher can
+   take a few seconds or more to generate a response.  Thhis is
+   frustrating for users, who are left staring at a blinking
+   cursor.
 
+   A small amount of feedback could help with this.
+   
 * Bugs
-
+  
 * Completed improvements
   
 ** CLOSED Turn on lexical scoping
@@ -115,6 +123,15 @@ Actually, this command can be useful to correct rendering issues that
 occasionally pop up in termal windows.  Lets leave it for now.
 
 ** CLOSED Implement Finger support
+   
+** CLOSED Improve download performance
+   This is actually easy to fix - the major problem at the moment is
+   the braindead way the incrementally-retrieved data is recorded:
+   (setq result-string (concat result-string next-bit)).
+   This is O(N^2).  Yuck!
+   
+   Okay, replacing this really does improve things.  Large gemini
+   downloads now seem occur at rates I'd expect.
 
 * Closed issues
   
index f1e7fb8..dec79ae 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -506,7 +506,7 @@ to ADDRESS."
       (let* ((kill-buffer-query-functions nil)
              (port (elpher-address-port address))
              (host (elpher-address-host address))
-             (selector-string "")
+             (selector-string-parts nil)
              (proc (open-network-stream "elpher-process"
                                         nil
                                         (if force-ipv4 (dns-query host) host)
@@ -538,8 +538,8 @@ to ADDRESS."
         (set-process-filter proc
                             (lambda (_proc string)
                               (cancel-timer timer)
-                              (setq selector-string
-                                    (concat selector-string string))))
+                              (setq selector-string-parts
+                                    (cons string selector-string-parts))))
         (set-process-sentinel proc
                               (lambda (_proc event)
                                 (condition-case the-error
@@ -553,7 +553,8 @@ to ADDRESS."
                                                  "\r\n"))))
                                      (t
                                       (cancel-timer timer)
-                                      (funcall renderer selector-string)
+                                      (funcall renderer (apply #'concat
+                                                               (reverse selector-string-parts)))
                                       (elpher-restore-pos)))
                                   (error
                                    (elpher-network-error address the-error))))))
@@ -1086,7 +1087,7 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d"
                  (port (let ((given-port (elpher-address-port address)))
                          (if (> given-port 0) given-port 79)))
                  (host (elpher-address-host address))
-                 (selector-string "")
+                 (selector-string-parts nil)
                  (proc (open-network-stream "elpher-process"
                                             nil
                                             (if force-ipv4 (dns-query host) host)
@@ -1107,8 +1108,8 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d"
             (set-process-filter proc
                                 (lambda (_proc string)
                                   (cancel-timer timer)
-                                  (setq selector-string
-                                        (concat selector-string string))))
+                                  (setq selector-string-parts
+                                        (cons string selector-string-parts))))
             (set-process-sentinel proc
                                   (lambda (_proc event)
                                     (condition-case the-error
@@ -1121,7 +1122,8 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d"
                                              (concat user "\r\n"))))
                                          (t
                                           (cancel-timer timer)
-                                          (funcall renderer selector-string)
+                                          (funcall renderer (apply #'concat
+                                                                   (reverse selector-string-parts)))
                                           (elpher-restore-pos)))))))
         (error
          (elpher-network-error address the-error))))))