[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf c3a308c 271/310: Optimize save performance over the
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf c3a308c 271/310: Optimize save performance over the temp file if such is used. Add |
Date: |
Sat, 28 Nov 2020 00:33:30 -0500 (EST) |
branch: externals/vlf
commit c3a308c835fa67b11bd4f7b191e961ffb12ac02a
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Optimize save performance over the temp file if such is used. Add
customization option whether to use temp file.
---
vlf-tune.el | 5 ++--
vlf-write.el | 85 ++++++++++++++++++++++++++++++++----------------------------
2 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/vlf-tune.el b/vlf-tune.el
index 82d7f43..eb0fa81 100644
--- a/vlf-tune.el
+++ b/vlf-tune.el
@@ -356,20 +356,21 @@ optimizing over TYPES up to MAX-IDX."
(if none-missing
(setq vlf-batch-size (* (1+ best-idx) vlf-tune-step)))))
-(defun vlf-tune-batch (types &optional linear)
+(defun vlf-tune-batch (types &optional linear file)
"Adjust `vlf-batch-size' to optimal value optimizing on TYPES.
TYPES is alist of elements that may be of form (type coef) or
non list values in which case coeficient is assumed 1.
Types can be :insert, :raw, :encode, :write, :hexl or :dehexlify.
If LINEAR is non nil, use brute-force. In case requested measurement
is missing, stop search and set `vlf-batch-size' to this value.
+FILE if given is filename to be used, otherwise `buffer-file-name'.
Suitable for multiple batch operations."
(if (eq vlf-tune-enabled t)
(let ((max-idx (1- (/ (min vlf-tune-max
(/ (1+ vlf-file-size) 2))
vlf-tune-step))))
(cond (linear (vlf-tune-linear types max-idx))
- ((file-remote-p buffer-file-name)
+ ((file-remote-p (or file buffer-file-name))
(vlf-tune-conservative types))
((<= 1 max-idx)
(if (< max-idx 3)
diff --git a/vlf-write.el b/vlf-write.el
index 709b7c6..5a656f7 100644
--- a/vlf-write.el
+++ b/vlf-write.el
@@ -29,6 +29,13 @@
(require 'vlf-base)
+(defcustom vlf-save-in-place 'ask
+ "Should VLF save in place when additional adjustment of file content\
+is needed."
+ :group 'vlf :type '(choice (const :tag "Always when applicable" t)
+ (const :tag "Ask when applicable" 'ask)
+ (const :tag "Never" nil)))
+
(defun vlf-write ()
"Write current chunk to file. Always return true to disable save.
If changing size of chunk, shift remaining file content."
@@ -59,42 +66,42 @@ If changing size of chunk, shift remaining file content."
(if (zerop size-change)
(vlf-tune-write nil nil vlf-start-pos t
(- vlf-end-pos vlf-start-pos))
- (let ((tramp-verbose (if (boundp 'tramp-verbose)
- (min tramp-verbose 2)))
- (pos (point))
- (font-lock font-lock-mode))
+ (let ((pos (point))
+ (font-lock font-lock-mode)
+ (batch-size vlf-batch-size)
+ time)
(font-lock-mode 0)
- (let ((batch-size vlf-batch-size)
- time)
- (if (or (file-remote-p buffer-file-name)
- (y-or-n-p "File content needs be adjusted till\
- end. Use temporary copy of the whole file (slower but safer)? "))
- (let ((file-tmp (make-temp-file
- (file-name-nondirectory
- buffer-file-name))))
- (setq time (float-time))
- (copy-file buffer-file-name file-tmp t t t t)
- (if (< 0 size-change)
- (vlf-file-shift-back size-change region-length
- file-tmp)
- (vlf-file-shift-forward (- size-change)
- region-length file-tmp))
- (rename-file file-tmp buffer-file-name t))
- (setq time (float-time))
- (if (< 0 size-change)
- (vlf-file-shift-back size-change region-length)
- (vlf-file-shift-forward (- size-change)
- region-length)))
- (if font-lock (font-lock-mode 1))
- (setq vlf-batch-size batch-size)
- (vlf-move-to-chunk-2 vlf-start-pos
- (if (< (- vlf-end-pos vlf-start-pos)
- vlf-batch-size)
- (+ vlf-start-pos vlf-batch-size)
- vlf-end-pos))
- (vlf-update-buffer-name)
- (goto-char pos)
- (message "Save took %f seconds" (- (float-time) time)))))))
+ (if (or (file-remote-p buffer-file-name)
+ (if (eq vlf-save-in-place 'ask)
+ (y-or-n-p "File content needs be adjusted\
+ till end. Use temporary copy of the whole file (slower but safer)? ")
+ (not vlf-save-in-place)))
+ (let ((file-tmp (make-temp-file
+ (file-name-nondirectory
+ buffer-file-name))))
+ (setq time (float-time))
+ (copy-file buffer-file-name file-tmp t t t t)
+ (if (< 0 size-change)
+ (vlf-file-shift-back size-change region-length
+ file-tmp)
+ (vlf-file-shift-forward (- size-change)
+ region-length file-tmp))
+ (rename-file file-tmp buffer-file-name t))
+ (setq time (float-time))
+ (if (< 0 size-change)
+ (vlf-file-shift-back size-change region-length)
+ (vlf-file-shift-forward (- size-change)
+ region-length)))
+ (if font-lock (font-lock-mode 1))
+ (setq vlf-batch-size batch-size)
+ (vlf-move-to-chunk-2 vlf-start-pos
+ (if (< (- vlf-end-pos vlf-start-pos)
+ vlf-batch-size)
+ (+ vlf-start-pos vlf-batch-size)
+ vlf-end-pos))
+ (vlf-update-buffer-name)
+ (goto-char pos)
+ (message "Save took %f seconds" (- (float-time) time))))))
(if hexl (vlf-tune-hexlify)))
(run-hook-with-args 'vlf-after-batch-functions 'write))
t)
@@ -129,7 +136,7 @@ back at WRITE-POS using FILE.
Return nil if EOF is reached, t otherwise."
(erase-buffer)
(vlf-verify-size t file)
- (vlf-tune-batch '(:raw :write)) ;insert speed over temp write file may defer
wildly
+ (vlf-tune-batch '(:raw :write) nil file) ;insert speed over temp write file
may defer wildly
(let ((read-end (min (+ read-pos vlf-batch-size) vlf-file-size))) ;compared
to the original file
(vlf-tune-insert-file-contents-literally read-pos read-end file)
(vlf-tune-write nil nil write-pos 0 (- read-end read-pos) file)
@@ -140,7 +147,7 @@ Return nil if EOF is reached, t otherwise."
WRITE-SIZE is byte length of saved chunk.
FILE if given is filename to be used, otherwise `buffer-file-name'.
Done by saving content up front and then writing previous batch."
- (vlf-tune-batch '(:raw :write))
+ (vlf-tune-batch '(:raw :write) nil file)
(let ((read-size (max vlf-batch-size size-change))
(read-pos vlf-end-pos)
(write-pos vlf-start-pos)
@@ -150,7 +157,7 @@ Done by saving content up front and then writing previous
batch."
(vlf-with-undo-disabled
(when (vlf-shift-batches read-size read-pos write-pos
write-size t file)
- (vlf-tune-batch '(:raw :write))
+ (vlf-tune-batch '(:raw :write) nil file)
(setq write-pos (+ read-pos size-change)
read-pos (+ read-pos read-size)
write-size read-size
@@ -159,7 +166,7 @@ Done by saving content up front and then writing previous
batch."
(let ((coding-system-for-write 'no-conversion))
(while (vlf-shift-batches read-size read-pos write-pos
write-size nil file)
- (vlf-tune-batch '(:raw :write))
+ (vlf-tune-batch '(:raw :write) nil file)
(setq write-pos (+ read-pos size-change)
read-pos (+ read-pos read-size)
write-size read-size
- [elpa] externals/vlf ece554a 231/310: Wording., (continued)
- [elpa] externals/vlf ece554a 231/310: Wording., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 069b2f5 240/310: Replace operations with respective vlf-tune wrappers., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fb05030 241/310: Add basic tune strategies., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e18a05b 247/310: Add linear search for tuning and prefer smaller batches., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 48a014f 250/310: Fix write measuring and endless loop in nearby approximation., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ee7409b 254/310: Tune batch size in more cases., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5651ee3 252/310: Rename vlf-tune-optimal to vlf-tune-batch., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 06b4f85 262/310: Respect disabled tune settings and move custom options., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 199209f 263/310: Fix vlf-tune-optimal-load with no optional arguments supplied., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 023ee70 267/310: Declare hexl functions to please byte compiler., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c3a308c 271/310: Optimize save performance over the temp file if such is used. Add,
Stefan Monnier <=
- [elpa] externals/vlf ce13609 278/310: Fix vlf-ediff at the borders of hexl buffers., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f43ada1 282/310: Fix byte compilation warnings., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 305d802 280/310: Use shared profiling info for encode, write and hexl operations., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5dd9e2c 281/310: Adjust address parts of hexlified buffer according to vlf-start-pos., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 68d6c1b 289/310: vlf-occur changes:, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0fa6248 288/310: Optimize unconditional chunk loading and prefer it in more cases of, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf bd5f9ca 286/310: Back to using per buffer profiling for encode speed., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 726f50b 294/310: Fix byte-compilation warnings on install., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf eaa3629 299/310: Fix cursor position after search, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ac1aa16 296/310: Standard naming for chunk update hooks., Stefan Monnier, 2020/11/28