[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf ca56498 259/310: Change vlf-tune-get-optimal to opt
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf ca56498 259/310: Change vlf-tune-get-optimal to optimize on total time of primitive |
Date: |
Sat, 28 Nov 2020 00:33:27 -0500 (EST) |
branch: externals/vlf
commit ca564988e054b93b4c830b856c208466858ad98d
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Change vlf-tune-get-optimal to optimize on total time of primitive
operations, also fix hexl timing functions not to book in cases where
hexl is already (not) active.
---
vlf-search.el | 4 ++++
vlf-tune.el | 52 +++++++++++++++++++++++++++++++++-------------------
2 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/vlf-search.el b/vlf-search.el
index 45fe1c9..6ef7b7d 100644
--- a/vlf-search.el
+++ b/vlf-search.el
@@ -158,6 +158,10 @@ 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
+ (if (derived-mode-p 'hexl-mode)
+ '(:hexl :dehexlify :insert :encode)
+ '(:insert :encode))))
(let* ((match-end (or (byte-to-position (- match-pos-end
vlf-start-pos))
(point-max)))
diff --git a/vlf-tune.el b/vlf-tune.el
index e3642bb..f406ad4 100644
--- a/vlf-tune.el
+++ b/vlf-tune.el
@@ -160,15 +160,17 @@ SIZE is number of bytes that are saved."
(defun vlf-tune-hexlify ()
"Activate `hexl-mode' and save time it takes."
- (let ((time (car (vlf-time (hexl-mode)))))
- (vlf-tune-add-measurement vlf-tune-hexl-bps
- hexl-max-address time)))
+ (or (derived-mode-p 'hexl-mode)
+ (let ((time (car (vlf-time (hexl-mode)))))
+ (vlf-tune-add-measurement vlf-tune-hexl-bps
+ hexl-max-address time))))
(defun vlf-tune-dehexlify ()
"Exit `hexl-mode' and save time it takes."
- (let ((time (car (vlf-time (hexl-mode-exit)))))
- (vlf-tune-add-measurement vlf-tune-dehexlify-bps
- hexl-max-address time)))
+ (if (derived-mode-p 'hexl-mode)
+ (let ((time (car (vlf-time (hexl-mode-exit)))))
+ (vlf-tune-add-measurement vlf-tune-dehexlify-bps
+ hexl-max-address time))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; tuning
@@ -238,20 +240,26 @@ If APPROXIMATE is t, do approximation for missing values."
index t))
0)))
-(defun vlf-tune-score (types index &optional approximate)
+(defun vlf-tune-score (types index &optional approximate time-max)
"Calculate cumulative speed over TYPES for INDEX.
-If APPROXIMATE is t, do approximation for missing values."
+If APPROXIMATE is t, do approximation for missing values.
+If TIME-MAX is non nil, return cumulative time instead of speed.
+If it is number, stop as soon as cumulative time gets equal or above."
(catch 'result
(let ((time 0)
- (size (* (1+ index) vlf-tune-step)))
- (dolist (el types (/ size time))
+ (size (* (1+ index) vlf-tune-step))
+ (cut-time (numberp time-max)))
+ (dolist (el types (if time-max time
+ (/ size time)))
(let ((bps (if (consp el)
(vlf-tune-assess (car el) (cadr el) index
approximate)
(vlf-tune-assess el 1 index approximate))))
(if (zerop bps)
(throw 'result nil)
- (setq time (+ time (/ size bps)))))))))
+ (setq time (+ time (/ size bps)))
+ (and cut-time (<= time-max time)
+ (throw 'result nil))))))))
(defun vlf-tune-conservative (types &optional index)
"Adjust `vlf-batch-size' to best nearby value over TYPES.
@@ -348,17 +356,23 @@ Suitable for multiple batch operations."
(vlf-tune-binary types 0 max-idx)))))))
(defun vlf-tune-get-optimal (types)
- "Get best batch size according to existing measurements over TYPES."
+ "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-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)))
+ (best-time-diff 1))
+ (while (and (not (zerop best-time-diff)) (< idx max-idx))
+ (let ((time-diff (vlf-tune-score types idx t
+ (1+ best-time-diff))))
+ (when time-diff
+ (setq time-diff (if (< 1 time-diff)
+ (- time-diff 1)
+ (- 1 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)))
- [elpa] externals/vlf fd90b3a 295/310: Use xdigit regex class in vlf-hexl-adjust-addresses., (continued)
- [elpa] externals/vlf fd90b3a 295/310: Use xdigit regex class in vlf-hexl-adjust-addresses., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf df677c1 302/310: Issue 35: make mode-line batch indicators more accurate, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a568d2d 307/310: packages/vlf: Update copyright dates and bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0ecb40a 124/310: Keep as much editing as possible when moving to intersecting chunk., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 86223ed 234/310: Fixes to hexl-mode integration., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9271f68 256/310: Add function to linearly search best batch size according to existing, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0d2c096 258/310: Restore batch size and hexl mode in case of failed search or occur., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b918791 265/310: Improve vlf performance with hexl-mode. Align batches to hexl-bits, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2e9ff70 238/310: Enlarge default batch size but keep is small on initial load of remote, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d85f3d4 246/310: Fix access to uninitialized measurements when tuning., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ca56498 259/310: Change vlf-tune-get-optimal to optimize on total time of primitive,
Stefan Monnier <=
- [elpa] externals/vlf 51d95ec 152/310: Add command to display batch starting from point., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 46e39a0 153/310: Version 1.0., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d1af56d 167/310: Fix opening of files for GNU Emacs 23., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 8ab1c6a 136/310: Disable undo and mark buffer as not modified when invoking search or, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf bb482f0 173/310: Fix file size determination for symbolic links., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9ffb968 172/310: Remove defadvice abort-if-file-too-large argument list so it works, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 386d856 179/310: Restore undo information after temporarily disabling it., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf deec75d 186/310: Enlarge minimum sample chunk for decoding size., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 516584e 187/310: Break VLF into components., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 27e3bbb 201/310: Reuse initial ediff session for all chunks., Stefan Monnier, 2020/11/28