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

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

[elpa] externals/vlf 9271f68 256/310: Add function to linearly search be


From: Stefan Monnier
Subject: [elpa] externals/vlf 9271f68 256/310: Add function to linearly search best batch size according to existing
Date: Sat, 28 Nov 2020 00:33:27 -0500 (EST)

branch: externals/vlf
commit 9271f68c05fb1566c1cdbd0d279ced9beaffb431
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Add function to linearly search best batch size according to existing
    measurements and offer it when interactively changing batch size.
---
 vlf-tune.el | 15 +++++++++++++++
 vlf.el      |  7 ++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/vlf-tune.el b/vlf-tune.el
index ba7703b..4868e2c 100644
--- a/vlf-tune.el
+++ b/vlf-tune.el
@@ -345,6 +345,21 @@ Suitable for multiple batch operations."
                    (vlf-tune-conservative types (/ max-idx 2))
                  (vlf-tune-binary types 0 max-idx)))))))
 
+(defun vlf-tune-get-optimal (types)
+  "Get best batch size according to existing measurements over TYPES."
+  (let ((max-idx (1- (/ (min vlf-tune-max (/ (1+ vlf-file-size) 2))
+                        vlf-tune-step)))
+        (best-idx 0)
+        (best-bps 0)
+        (idx 0))
+    (while (< idx max-idx)
+      (let ((bps (vlf-tune-score types idx t)))
+        (and bps (< best-bps bps)
+             (setq best-idx idx
+                   best-bps bps)))
+      (setq idx (1+ idx)))
+    (* (1+ best-idx) vlf-tune-step)))
+
 (provide 'vlf-tune)
 
 ;;; vlf-tune.el ends here
diff --git a/vlf.el b/vlf.el
index 0aae3ab..fad68b3 100644
--- a/vlf.el
+++ b/vlf.el
@@ -259,7 +259,12 @@ with the prefix argument DECREASE it is halved."
 
 (defun vlf-set-batch-size (size)
   "Set batch to SIZE bytes and update chunk."
-  (interactive (list (read-number "Size in bytes: " vlf-batch-size)))
+  (interactive
+   (list (read-number "Size in bytes: "
+                      (vlf-tune-get-optimal
+                       (if (derived-mode-p 'hexl-mode)
+                           '(:hexl :dehexlify :insert :encode)
+                         '(:insert :encode))))))
   (setq vlf-batch-size size)
   (vlf-move-to-batch vlf-start-pos))
 



reply via email to

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