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

Respect disabled tune settings and move custom options.

This commit is contained in:
Andrey Kotlarski 2014-09-08 02:21:09 +03:00
parent ff06509caa
commit 06b4f856ac
3 changed files with 56 additions and 46 deletions

View File

@ -29,11 +29,6 @@
(require 'vlf-tune) (require 'vlf-tune)
(defcustom vlf-batch-size 1000000
"Defines how large each batch of file data initially is (in bytes)."
:group 'vlf :type 'integer)
(put 'vlf-batch-size 'permanent-local t)
(defcustom vlf-before-chunk-update nil (defcustom vlf-before-chunk-update nil
"Hook that runs before chunk update." "Hook that runs before chunk update."
:group 'vlf :type 'hook) :group 'vlf :type 'hook)

View File

@ -23,11 +23,18 @@
;;; Commentary: ;;; Commentary:
;; This package provides wrappers for basic chunk operations that add ;; This package provides wrappers for basic chunk operations that add
;; time statistics and automatic tuning of `vlf-batch-size' for ;; profiling and automatic tuning of `vlf-batch-size'.
;; optimal performance.
;;; Code: ;;; Code:
(defgroup vlf nil "View Large Files in Emacs."
:prefix "vlf-" :group 'files)
(defcustom vlf-batch-size 1000000
"Defines how large each batch of file data initially is (in bytes)."
:group 'vlf :type 'integer)
(put 'vlf-batch-size 'permanent-local t)
(defcustom vlf-tune-enabled t (defcustom vlf-tune-enabled t
"Whether to allow automatic change of batch size. "Whether to allow automatic change of batch size.
If nil, completely disable. If `stats', maintain measure statistics, If nil, completely disable. If `stats', maintain measure statistics,
@ -56,7 +63,7 @@ but don't change batch size. If t, measure and change."
"Maximum batch size in bytes when auto tuning." "Maximum batch size in bytes when auto tuning."
:group 'vlf :type 'integer) :group 'vlf :type 'integer)
(defcustom vlf-tune-step (round vlf-tune-max 1000) (defcustom vlf-tune-step (/ vlf-tune-max 1000)
"Step used for tuning in bytes." "Step used for tuning in bytes."
:group 'vlf :type 'integer) :group 'vlf :type 'integer)
@ -100,7 +107,7 @@ but don't change batch size. If t, measure and change."
(max 0 (1- (min (round size step) (round vlf-tune-max step)))))) (max 0 (1- (min (round size step) (round vlf-tune-max step))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; bookkeeping ;;; profiling
(defun vlf-tune-initialize-measurement () (defun vlf-tune-initialize-measurement ()
"Initialize measurement vector." "Initialize measurement vector."
@ -125,9 +132,12 @@ VEC is a vector of (mean time . count) elements ordered by size."
(defmacro vlf-time (&rest body) (defmacro vlf-time (&rest body)
"Get timing consed with result of BODY execution." "Get timing consed with result of BODY execution."
`(let ((time (float-time)) `(if vlf-tune-enabled
(result (progn ,@body))) (let* ((time (float-time))
(cons (- (float-time) time) result))) (result (progn ,@body)))
(cons (- (float-time) time) result))
(let ((result (progn ,@body)))
(cons nil result))))
(defun vlf-tune-insert-file-contents (start end) (defun vlf-tune-insert-file-contents (start end)
"Extract decoded file bytes START to END and save time it takes." "Extract decoded file bytes START to END and save time it takes."
@ -364,40 +374,48 @@ Suitable for multiple batch operations."
Best considered where primitive operations total is closest to Best considered where primitive operations total is closest to
`vlf-tune-load-time'. If MIN-IDX and MAX-IDX are given, `vlf-tune-load-time'. If MIN-IDX and MAX-IDX are given,
confine search to this region." confine search to this region."
(or max-idx (if vlf-tune-enabled
(setq max-idx (min max-idx (1- (/ (min vlf-tune-max (progn
(/ (1+ vlf-file-size) 2)) (or max-idx
vlf-tune-step))))) (setq max-idx (min max-idx
(let* ((idx (max 0 (or min-idx 0))) (1- (/ (min vlf-tune-max
(best-idx idx) (/ (1+ vlf-file-size) 2))
(best-time-diff vlf-tune-load-time) vlf-tune-step)))))
(all-less t) (let* ((idx (max 0 (or min-idx 0)))
(all-more t)) (best-idx idx)
(while (and (not (zerop best-time-diff)) (< idx max-idx)) (best-time-diff vlf-tune-load-time)
(let ((time-diff (vlf-tune-score types idx t (all-less t)
(+ vlf-tune-load-time (all-more t))
best-time-diff)))) (while (and (not (zerop best-time-diff)) (< idx max-idx))
(when time-diff (let ((time-diff (vlf-tune-score types idx t
(setq time-diff (if (< vlf-tune-load-time time-diff) (+ vlf-tune-load-time
(progn (setq all-less nil) best-time-diff))))
(- time-diff vlf-tune-load-time)) (when time-diff
(setq all-more nil) (setq time-diff (if (< vlf-tune-load-time time-diff)
(- vlf-tune-load-time time-diff))) (progn (setq all-less nil)
(if (< time-diff best-time-diff) (- time-diff
(setq best-idx idx vlf-tune-load-time))
best-time-diff time-diff)))) (setq all-more nil)
(setq idx (1+ idx))) (- vlf-tune-load-time time-diff)))
(* vlf-tune-step (1+ (cond ((eq all-less all-more) best-idx) (if (< time-diff best-time-diff)
(all-less max-idx) (setq best-idx idx
(t min-idx)))))) best-time-diff time-diff))))
(setq idx (1+ idx)))
(* vlf-tune-step (1+ (cond ((or (zerop best-time-diff)
(eq all-less all-more))
best-idx)
(all-less max-idx)
(t min-idx))))))
vlf-batch-size))
(defun vlf-tune-load (types &optional region) (defun vlf-tune-load (types &optional region)
"Adjust `vlf-batch-size' slightly to better load time. "Adjust `vlf-batch-size' slightly to better load time.
Optimize on TYPES on the nearby REGION. Use 2 if REGION is nil." Optimize on TYPES on the nearby REGION. Use 2 if REGION is nil."
(or region (setq region 2)) (when (eq vlf-tune-enabled t)
(let ((idx (vlf-tune-closest-index vlf-batch-size))) (or region (setq region 2))
(setq vlf-batch-size (vlf-tune-optimal-load types (- idx region) (let ((idx (vlf-tune-closest-index vlf-batch-size)))
(+ idx 1 region))))) (setq vlf-batch-size (vlf-tune-optimal-load types (- idx region)
(+ idx 1 region))))))
(provide 'vlf-tune) (provide 'vlf-tune)

5
vlf.el
View File

@ -39,8 +39,7 @@
;;; Code: ;;; Code:
(defgroup vlf nil "View Large Files in Emacs." (require 'vlf-base)
:prefix "vlf-" :group 'files)
(defcustom vlf-before-batch-functions nil (defcustom vlf-before-batch-functions nil
"Hook that runs before multiple batch operations. "Hook that runs before multiple batch operations.
@ -54,8 +53,6 @@ One argument is supplied that specifies current action. Possible
values are: `write', `ediff', `occur', `search', `goto-line'." values are: `write', `ediff', `occur', `search', `goto-line'."
:group 'vlf :type 'hook) :group 'vlf :type 'hook)
(require 'vlf-base)
(autoload 'vlf-write "vlf-write" "Write current chunk to file." t) (autoload 'vlf-write "vlf-write" "Write current chunk to file." t)
(autoload 'vlf-re-search-forward "vlf-search" (autoload 'vlf-re-search-forward "vlf-search"
"Search forward for REGEXP prefix COUNT number of times." t) "Search forward for REGEXP prefix COUNT number of times." t)