mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 12:05:31 +00:00
Replace usage of conservative tune in single batch operations with load
tuning.
This commit is contained in:
parent
ca564988e0
commit
9b6657bcc5
@ -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))))
|
||||
|
49
vlf-tune.el
49
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)
|
||||
|
||||
|
12
vlf.el
12
vlf.el
@ -172,7 +172,7 @@ 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)
|
||||
(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)))
|
||||
@ -191,7 +191,7 @@ 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)
|
||||
(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)))))
|
||||
@ -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,7 +271,7 @@ 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)
|
||||
(vlf-tune-load (if (derived-mode-p 'hexl-mode)
|
||||
'(:hexl :dehexlify :insert :encode)
|
||||
'(:insert :encode)))
|
||||
(vlf-move-to-batch 0))
|
||||
@ -280,7 +280,7 @@ with the prefix argument DECREASE it is halved."
|
||||
"Jump to end of file content."
|
||||
(interactive)
|
||||
(vlf-verify-size)
|
||||
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
|
||||
(vlf-tune-load (if (derived-mode-p 'hexl-mode)
|
||||
'(:hexl :dehexlify :insert :encode)
|
||||
'(:insert :encode)))
|
||||
(vlf-move-to-batch vlf-file-size))
|
||||
@ -298,7 +298,7 @@ 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)
|
||||
(vlf-tune-load (if (derived-mode-p 'hexl-mode)
|
||||
'(:hexl :dehexlify :insert :encode)
|
||||
'(:insert :encode)))
|
||||
(vlf-move-to-batch (* (1- n) vlf-batch-size)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user