Criticism of jit-lock--antiblink-post-command

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Criticism of jit-lock--antiblink-post-command

Alan Mackenzie
Hello, João.

I've been taking a closer look at the jit-lock antiblink functionality,
and some things seem to want comment.

Firstly, jit-lock-antiblink-grace is tested for being nil, yet is
declared in its customization scheme only as a number.  Should it not
alternatively be customizable to nil instead of a number?  This would
enable a user to disable it without having to read the source code and
use a setq.  The variable's doc string should surely also document this
possibility.

You have mentioned that this antiblink is redundant when using things
like electric-pair-mode, in which case the mode merely slows down the
processing.  The same is true of CC Mode, where there are no
unterminated strings.  These are good reasons for making antiblink easy
to disable.

In jit-lock--antiblink-post-command, you create lots of markers, one per
command.  You don't do anything to get rid of them, beyond waiting for
the next garbage collection to do its work.  This could easily lead to
several hundred markers slowing down operations in a buffer.  Maybe.
Page "Overview of Markers" in the Elisp manual recommends making them
point nowhere when you have finished with them, using (set-marker m
nil).  Please consider doing this.

--
Alan Mackenzie (Nuremberg, Germany).

Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Stefan Monnier
> You have mentioned that this antiblink is redundant when using things
> like electric-pair-mode, in which case the mode merely slows down the
> processing.  The same is true of CC Mode, where there are no
> unterminated strings.

There's are still the issues of unterminated comments.

> These are good reasons for making antiblink easy to disable.

The intention is that when it's not useful it's harmless.
IOW if there's a good reason to turn it off, it's probably a bug.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

João Távora
In reply to this post by Alan Mackenzie
Hi Alan,

Indeed it makes sense to let the customizer explicitly
choose nil.  I will fix that. Doesn't the docstring already
say it can be nil?  Maybe you missed it at the end
of such a long docstring (I will make it shorter per Eli's
request).

It's easy to toggle the variable to nil buffer-locally, but as
Stefan said, it should be harmless when left on.

Regarding the markers, I'll have a look. But it seems
premature optimization.  Remember that I benchmarked
this and it presented no real problem.

João

Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Eli Zaretskii
In reply to this post by Stefan Monnier
> From: Stefan Monnier <[hidden email]>
> Cc: João Távora <[hidden email]>,  Eli
>  Zaretskii <[hidden email]>,
>   [hidden email]
> Date: Tue, 26 Nov 2019 15:51:04 -0500
>
> > These are good reasons for making antiblink easy to disable.
>
> The intention is that when it's not useful it's harmless.
> IOW if there's a good reason to turn it off, it's probably a bug.

I don't think I agree.  A post-command-hook that is not useful just
takes CPU cycles, and likewise a timer which does nothing when its
function is invoked.

And in any case, a feature that changes behavior should have a knob to
disable it.

Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Phil Sainty
In reply to this post by João Távora
On 2019-11-27 10:09, João Távora wrote:
> Regarding the markers, I'll have a look. But it seems
> premature optimization.

AFAIK that one is standard best practice for working with
markers, even if you're not expecting it to make a noticeable
difference.


-Phil


Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

João Távora
On Wed, Nov 27, 2019 at 5:54 AM Phil Sainty <[hidden email]> wrote:
>
> On 2019-11-27 10:09, João Távora wrote:
> > Regarding the markers, I'll have a look. But it seems
> > premature optimization.
>
> AFAIK that one is standard best practice for working with
> markers,

I understand that, and I think I've seen cases where it
matters.  Just this one doesn't seem to (for now, at
least). But it's very easy to fix and doesn't introduce
particular complexity in this case, so consider it done.

> even if you're not expecting it to make a noticeable
> difference.

Hmm, I do expect best practices to make noticeable
differences, at least for some value of "noticeable".
Otherwise, it becomes cargo-culting, don't you
think?

João

Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Stefan Monnier
>> even if you're not expecting it to make a noticeable
>> difference.
> Hmm, I do expect best practices to make noticeable
> differences, at least for some value of "noticeable".

In the case of manually deleting markers, it tends to be negligible in
most cases, but it can and does become noticeable when pushed harder.

We arguably could/should replace the singly-linked-list of markers with
another data structure that doesn't suffer from those algorithmic
problems, but ...


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Stefan Monnier
In reply to this post by Eli Zaretskii
>> The intention is that when it's not useful it's harmless.
>> IOW if there's a good reason to turn it off, it's probably a bug.
> I don't think I agree.  A post-command-hook that is not useful just
> takes CPU cycles, and likewise a timer which does nothing when its
> function is invoked.

AFAIK we don't try very hard to avoid such waste.
E.g. every time we run redisplay, it will check at every position if
there is a `display` or `invisible` property, even in those buffers
where no code ever has nor ever will add one of those properties.
[ This is just a random example, we have loads more, of course.  ]

> And in any case, a feature that changes behavior should have a knob to
> disable it.

We like such knobs in Emacs, indeed.  My argument was not against having
such a knob (which is already present in the suggested patch, AFAIK) but
in favor of keeping the feature enabled by default and encouraging
people to report problems when the encounter them rather than just turn
off the feature.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Criticism of jit-lock--antiblink-post-command

Eli Zaretskii
> From: Stefan Monnier <[hidden email]>
> Cc: [hidden email],  [hidden email],  [hidden email]
> Date: Wed, 27 Nov 2019 08:46:41 -0500
>
> >> The intention is that when it's not useful it's harmless.
> >> IOW if there's a good reason to turn it off, it's probably a bug.
> > I don't think I agree.  A post-command-hook that is not useful just
> > takes CPU cycles, and likewise a timer which does nothing when its
> > function is invoked.
>
> AFAIK we don't try very hard to avoid such waste.

We should, though.

> E.g. every time we run redisplay, it will check at every position if
> there is a `display` or `invisible` property, even in those buffers
> where no code ever has nor ever will add one of those properties.

No, the display engine doesn't check for these properties at every
position, it only checks that at positions where some property
changes (by looking at the interval tree).

And properties can be added manually, not just by code, btw.

> > And in any case, a feature that changes behavior should have a knob to
> > disable it.
>
> We like such knobs in Emacs, indeed.  My argument was not against having
> such a knob

Well, by saying "if it needs to be turned off, it's a bug", you seemed
to be saying that it doesn't need to be turned off.  Apologies for my
misunderstanding.