branch: externals/vlf
commit 9271f68c05fb1566c1cdbd0d279ced9beaffb431
Author: Andrey Kotlarski <[email protected]>
Commit: Andrey Kotlarski <[email protected]>
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))