Subject: Re: bug#12747: 23.4; diff-auto-refine-mode process only last hunk in diff (must ALL).

From: Noam Postavsky <[email-masked]>
Date: Wed, 11 Jul 2018 20:28:47 -0400

merge 12747 16798 18128 21744
tags 12747 fixed
close 12747 27.1
quit

Stefan Monnier <[email-masked]> writes:

> This is not a bug.  IIUC you'd like the refinement to be done in any
> hunk that is ever displayed, right?
> If so, that is a valid request for enhancement, and I fully agree.
> If someone is interested in implementing it, here's how I think it would
> have to work:
> - add a font-lock-keywords rule in diff-mode which simply registers the
>   region displayed in a buffer-local var `diff--regions-displayed'.
> - have an idle timer that checks `diff--regions-displayed' and refines
>   all the hunks in those regions (and it should also font-lock those
>   hunks at the same time, so that if some of the hunk is not yet
>   displayed and not yet font-locked, displaying it later on won't cause
>   re-refining the hunk).

I think you've implemented this now [1: f8b1e40fb6], though not quite in
the way you describe (I don't see any timers).

[1: f8b1e40fb6]: 2018-07-10 22:52:21 -0400
  * lisp/vc/diff-mode.el: Perform hunk refinement from font-lock
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=f8b1e40fb63b0a6bc6692cc0bc84e5f5e65c2644

This reminds that magit users found binding write-region-inhibit-fsync
around smerge-refine-regions made a noticable performance difference.
So should we add something like this?

>From e5f3cf973c37ddaca92cc819d95d896ca0d869c7 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Wed, 11 Jul 2018 20:13:25 -0400
Subject: [PATCH] Speed up smerge-refine-regions by avoiding fsync

* lisp/vc/smerge-mode.el (smerge-refine-regions): Bind
write-region-inhibit-fsync to t.
---
 lisp/vc/smerge-mode.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/smerge-mode.el b/lisp/vc/smerge-mode.el
index cb51fbab8e..cb9880c80d 100644
--- a/lisp/vc/smerge-mode.el
+++ b/lisp/vc/smerge-mode.el
@@ -1075,9 +1075,10 @@ smerge-refine-regions
           (if smerge-refine-weight-hack (make-hash-table :test #'equal))))
     (unless (markerp beg1) (setq beg1 (copy-marker beg1)))
     (unless (markerp beg2) (setq beg2 (copy-marker beg2)))
-    ;; Chop up regions into smaller elements and save into files.
-    (smerge--refine-chopup-region beg1 end1 file1 preproc)
-    (smerge--refine-chopup-region beg2 end2 file2 preproc)
+    (let ((write-region-inhibit-fsync t)) ; Don't fsync temp files.
+      ;; Chop up regions into smaller elements and save into files.
+      (smerge--refine-chopup-region beg1 end1 file1 preproc)
+      (smerge--refine-chopup-region beg2 end2 file2 preproc))
 
     ;; Call diff on those files.
     (unwind-protect
-- 
2.11.0