[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 9b6657b 260/310: Replace usage of conservative tune
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 9b6657b 260/310: Replace usage of conservative tune in single batch operations with load |
Date: |
Sat, 28 Nov 2020 00:33:27 -0500 (EST) |
branch: externals/vlf
commit 9b6657bcc56e76c6b56cf633b11621e5480f61e3
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Replace usage of conservative tune in single batch operations with load
tuning.
---
vlf-search.el | 2 +-
vlf-tune.el | 49 ++++++++++++++++++++++++++++++++++++-------------
vlf.el | 32 ++++++++++++++++----------------
3 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/vlf-search.el b/vlf-search.el
index 6ef7b7d..33dcc42 100644
--- a/vlf-search.el
+++ b/vlf-search.el
@@ -158,7 +158,7 @@ Return nil if nothing found."
(if success
(vlf-update-buffer-name)
(vlf-move-to-chunk match-chunk-start match-chunk-end))
- (setq vlf-batch-size (vlf-tune-get-optimal
+ (setq vlf-batch-size (vlf-tune-optimal-load
(if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode))))
diff --git a/vlf-tune.el b/vlf-tune.el
index f406ad4..f9c0ca0 100644
--- a/vlf-tune.el
+++ b/vlf-tune.el
@@ -56,10 +56,14 @@ but don't change batch size. If t, measure and change."
"Maximum batch size in bytes when auto tuning."
:group 'vlf :type 'integer)
-(defcustom vlf-tune-step (/ vlf-tune-max 1000)
+(defcustom vlf-tune-step (round vlf-tune-max 1000)
"Step used for tuning in bytes."
:group 'vlf :type 'integer)
+(defcustom vlf-tune-load-time 1.0
+ "How many seconds should batch take to load for best user experience."
+ :group 'vlf :type 'float)
+
(defvar vlf-tune-insert-bps nil
"Vector of bytes per second insert measurements.")
(make-variable-buffer-local 'vlf-tune-insert-bps)
@@ -355,26 +359,45 @@ 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)
+(defun vlf-tune-optimal-load (types &optional min-idx max-idx)
"Get best batch size according to existing measurements over TYPES.
-Best is considered where primitive operations total closest to second."
- (let ((max-idx (1- (/ (min vlf-tune-max (/ (1+ vlf-file-size) 2))
- vlf-tune-step)))
- (idx 0)
- (best-idx 0)
- (best-time-diff 1))
+Best considered where primitive operations total is closest to
+`vlf-tune-load-time'. If MIN-IDX and MAX-IDX are given,
+confine search to this region."
+ (or max-idx
+ (setq max-idx (min max-idx (1- (/ (min vlf-tune-max
+ (/ (1+ vlf-file-size) 2))
+ vlf-tune-step)))))
+ (let* ((idx (max 0 (or min-idx 0)))
+ (best-idx idx)
+ (best-time-diff vlf-tune-load-time)
+ (all-less t)
+ (all-more t))
(while (and (not (zerop best-time-diff)) (< idx max-idx))
(let ((time-diff (vlf-tune-score types idx t
- (1+ best-time-diff))))
+ (+ vlf-tune-load-time
+ best-time-diff))))
(when time-diff
- (setq time-diff (if (< 1 time-diff)
- (- time-diff 1)
- (- 1 time-diff)))
+ (setq time-diff (if (< vlf-tune-load-time time-diff)
+ (progn (setq all-less nil)
+ (- time-diff vlf-tune-load-time))
+ (setq all-more nil)
+ (- vlf-tune-load-time time-diff)))
(if (< time-diff best-time-diff)
(setq best-idx idx
best-time-diff time-diff))))
(setq idx (1+ idx)))
- (* (1+ best-idx) vlf-tune-step)))
+ (* vlf-tune-step (1+ (cond ((eq all-less all-more) best-idx)
+ (all-less max-idx)
+ (t min-idx))))))
+
+(defun vlf-tune-load (types &optional region)
+ "Adjust `vlf-batch-size' slightly to better load time.
+Optimize on TYPES on the nearby REGION. Use 2 if REGION is nil."
+ (or region (setq region 2))
+ (let ((idx (vlf-tune-closest-index vlf-batch-size)))
+ (setq vlf-batch-size (vlf-tune-optimal-load types (- idx region)
+ (+ idx 1 region)))))
(provide 'vlf-tune)
diff --git a/vlf.el b/vlf.el
index f9073d8..feeb983 100644
--- a/vlf.el
+++ b/vlf.el
@@ -172,9 +172,9 @@ When prefix argument is negative
append next APPEND number of batches to the existing buffer."
(interactive "p")
(vlf-verify-size)
- (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
- '(:hexl :dehexlify :insert :encode)
- '(:insert :encode)))
+ (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode)))
(let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
vlf-file-size))
(start (if (< append 0)
@@ -191,9 +191,9 @@ When prefix argument is negative
(interactive "p")
(if (zerop vlf-start-pos)
(error "Already at BOF"))
- (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
- '(:hexl :dehexlify :insert :encode)
- '(:insert :encode)))
+ (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode)))
(let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
(end (if (< prepend 0)
vlf-end-pos
@@ -261,7 +261,7 @@ with the prefix argument DECREASE it is halved."
"Set batch to SIZE bytes and update chunk."
(interactive
(list (read-number "Size in bytes: "
- (vlf-tune-get-optimal
+ (vlf-tune-optimal-load
(if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode))))))
@@ -271,18 +271,18 @@ with the prefix argument DECREASE it is halved."
(defun vlf-beginning-of-file ()
"Jump to beginning of file content."
(interactive)
- (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
- '(:hexl :dehexlify :insert :encode)
- '(:insert :encode)))
+ (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode)))
(vlf-move-to-batch 0))
(defun vlf-end-of-file ()
"Jump to end of file content."
(interactive)
(vlf-verify-size)
- (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
- '(:hexl :dehexlify :insert :encode)
- '(:insert :encode)))
+ (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode)))
(vlf-move-to-batch vlf-file-size))
(defun vlf-revert (&optional _auto noconfirm)
@@ -298,9 +298,9 @@ Ask for confirmation if NOCONFIRM is nil."
(defun vlf-jump-to-chunk (n)
"Go to to chunk N."
(interactive "nGoto to chunk: ")
- (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
- '(:hexl :dehexlify :insert :encode)
- '(:insert :encode)))
+ (vlf-tune-load (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode)))
(vlf-move-to-batch (* (1- n) vlf-batch-size)))
(defun vlf-no-modifications ()
- [elpa] externals/vlf 8c61b77 222/310: Fix when batch hooks are run for occur and save., (continued)
- [elpa] externals/vlf 8c61b77 222/310: Fix when batch hooks are run for occur and save., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 6476c1b 227/310: Update README, wording, add links and information on hooks., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 8ba5bea 229/310: Don't run vlf-after-batch-functions hook in vlf-build-occur., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 569e4b2 237/310: Don't ask needles questions on changing helm batch and restore undo, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 1f9ba7c 230/310: Use derived-mode-p., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 32ff2cb 239/310: Add bookkeeping module., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5379943 242/310: Save times instead of speeds, compare on cumulative speed when tuning., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0d9cc8e 245/310: Don't measure encoding of too small region when adjusting chunk start, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e8bb4a9 248/310: Apply batch size tuning on adjacent moves, search, save adjusting and, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d526ea8 257/310: Apply and restore batch size in more cases., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9b6657b 260/310: Replace usage of conservative tune in single batch operations with load,
Stefan Monnier <=
- [elpa] externals/vlf 2c660b0 269/310: Fix positive goto-line search and make highlighting of match optional., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3cfa9b1 273/310: Refactor vlf-query-replace and don't adjust batch size if only, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 61599a0 274/310: Change linear tune to search only known measures and use it to, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a9c14e2 268/310: Add regexp query replace over whole file command., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 673ae08 277/310: Lower tramp verbosity level., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ac8d400 276/310: Fixes to hexl-mode activation., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f63ea96 272/310: Document new query replace and save options., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e4a2e80 266/310: Optimize goto-line for hexl-mode, no need to search., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 7b9befe 275/310: - don't load unnecessary data at the end of search or occur, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 842569a 270/310: Add ability to use temporary file when adjusting content on save., Stefan Monnier, 2020/11/28