emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb efd9e15 12/21: Provide an alternate threaded versi


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb efd9e15 12/21: Provide an alternate threaded version of ebdb-initialize
Date: Sun, 17 Sep 2017 15:32:47 -0400 (EDT)

branch: externals/ebdb
commit efd9e1512e00e4d93cfbed157f9c03164ebe76ac
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Provide an alternate threaded version of ebdb-initialize
    
    Ref #53
    
    * ebdb.el (ebdb-initialize): New function that calls thread-yield
      every 10 records. This won't do anything at all by default.
      (ebdb-load): Use the function if threading is available.
---
 ebdb.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/ebdb.el b/ebdb.el
index 7db7cb2..accdcad 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4933,7 +4933,9 @@ important work is done by the `ebdb-db-load' method."
        ;; We're migrating from a version of BBDB.
        (ebdb-migrate-from-bbdb))
     (message "Initializing EBDB records...")
-    (ebdb-initialize)
+    (if (fboundp 'make-thread)
+       (ebdb-initialize-threadwise)
+      (ebdb-initialize))
     (message "Initializing EBDB records... done")
     ;; Users will expect the same ordering as `ebdb-sources'
     (setq ebdb-db-list (nreverse ebdb-db-list))
@@ -4958,12 +4960,27 @@ important work is done by the `ebdb-db-load' method."
 ;; is searched.
 (defun ebdb-initialize (&optional records)
   "After all databases are loaded, initialize the records.
-
 This results in the creation of all the secondary data
 structures: label lists, `ebdb-org-hashtable', record caches,
 etc."
   (mapcar #'ebdb-init-record (or records ebdb-record-tracker)))
 
+(defun ebdb-initialize-threadwise (&optional records)
+  "Exactly the same as `ebdb-initialize', but yields thread.
+If Emacs has threading, then `ebdb-load' will call this function
+in its own thread, and the thread will be yielded after every ten
+record initializations.  Note that by itself this will have no
+impact whatsoever on EBDB load times.  It's up to the user to
+interleave it with other thread-yielding operations to create an
+actual speedup."
+  (let ((c 0))
+    (mapcar
+     (lambda (r)
+       (ebdb-init-record r)
+       (when (= (mod (cl-incf c) 10) 0)
+        (thread-yield)))
+     (or records ebdb-record-tracker))))
+
 (defun ebdb-address-continental-p (address)
   "Return non-nil if ADDRESS is a continental address.
 This is done by comparing the postcode to `ebdb-continental-postcode-regexp'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]