emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keeping replace-buffer-contents runtime in bounds


From: Eli Zaretskii
Subject: Re: Keeping replace-buffer-contents runtime in bounds
Date: Sun, 17 Feb 2019 17:50:45 +0200

> From: Tassilo Horn <address@hidden>
> Date: Sat, 16 Feb 2019 21:09:40 +0100
> 
> 1. There's some too_expensive field of the context struct passed to
>    compareseq which has quite some effect on the speed.  I couldn't find
>    any negative sides in using a much lower value than we originally
>    used (1,000,000).  However, maybe it's just my use-case.  This is now
>    exposed as an optional argument of replace-buffer-contents.
> 
> 2. The too_expensive field is not enough.  If the buffer contents and
>    the contents of the replacement buffer become too large and there are
>    too many differences, it may still take ages.
> 
> So now I added some code which allows compareseq to abort early if the
> difference computation is too costly.  Initially I've tried to use the
> number of differences found so far plus a max value.  However, after
> using that some days I noticed that this is not a too good measure.
> Sometimes there were gazillion of differences, yet the difference
> computation was quick.  But other times the number of differences was
> lower but still it took ages (most probably because the json was
> larger).
> 
> In the end I settled for a maximum number of seconds one can define by
> setting a new variable replace-buffer-contents-max-secs, so that you can
> define what's still acceptable in the respective use-case.  (Actually,
> if you set that to 1.5 or so, it may still run for 2 or more seconds
> because the EARLY_ABORT expression isn't tested at regular intervals or
> rather it is, but the intervals don't take equally long.)
> 
> If that number of seconds is over, compareseq returns early and
> replace-buffer-contents falls back to plain delete and insert.

The gotcha about aborting after more than the time-out value should be
mentioned in the doc string.

Thanks for working on this.  My only other comment is that maybe we
should allow passing the time-out value via the function's arguments,
not via a global variable.  It seems to me the time-out will be used
in more use cases than MAX-COSTS, and in any case treating these two
differently API-wise sounds strangely inconsistent.

> This is my first C encounter in emacs, so please feel free to nit-pick.

Nitpicking:

> +  DEFVAR_LISP ("replace-buffer-contents-max-secs",
> +            Vreplace_buffer_contents_max_secs,
> +            doc: /* If differencing the two buffers takes longer than this,
> +`replace-buffer-contents' falls back to a plain delete and insert.  */);

The first sentence of a doc string should not be longer than 79
characters.  (But if you agree with me, this variable will go away, so
it's a moot point.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]