1
0
mirror of https://github.com/m00natic/vlfi.git synced 2024-10-05 18:30:51 +01:00

Replace usage of conservative tune in single batch operations with load

tuning.
This commit is contained in:
Andrey Kotlarski 2014-09-07 22:10:56 +03:00
parent ca564988e0
commit 9b6657bcc5
3 changed files with 53 additions and 30 deletions

View File

@ -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))))

View File

@ -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)

32
vlf.el
View File

@ -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 ()