GNU bug report logs - #45379
28.0.50; Degraded Performance of describe-buffer-bindings

Previous Next

Package: emacs;

Reported by: styang <at> fastmail.com

Date: Wed, 23 Dec 2020 06:03:01 UTC

Severity: normal

Tags: confirmed, fixed, patch

Merged with 47494, 47565, 48812

Found in version 28.0.50

Fixed in version 28.1

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45379 in the body.
You can then email your comments to 45379 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Wed, 23 Dec 2020 06:03:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to styang <at> fastmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 23 Dec 2020 06:03:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: styang <at> fastmail.com
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; Degraded Performance of describe-buffer-bindings
Date: Wed, 23 Dec 2020 00:01:53 -0600
`describe-buffer-bindings` has become significantly slower since the
following commit

a649034336 * bad Don't show key ranges if shadowed by different commands

This also makes `describe-bindings` and anything depending on it hardly
usable. For me, it takes about 2 seconds on vanilla Emacs in an org-mode
buffer, and a few minutes on my Emacs configuration (was almost instant
before the offending commit).

-- 
Sheng Yang(杨圣), PhD student
Computer Science Department
University of Maryland, College Park
E-mail: styang <at> fastmail.com
E-mail(old): yangsheng6810 <at> gmail.com




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Fri, 08 Jan 2021 16:49:02 GMT) Full text and rfc822 format available.

Message #8 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: "Sheng Yang" <styang <at> fastmail.com>
To: "Juri Linkov" <juri <at> linkov.net>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, Stefan Kangas <stefan <at> marxist.se>,
 martin rudalics <rudalics <at> gmx.at>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Eli Zaretskii <eliz <at> gnu.org>, 45379 <at> debbugs.gnu.org
Subject: Re: 28.0.50; Degraded Performance of describe-buffer-bindings
Date: Fri, 08 Jan 2021 10:47:47 -0600
[Message part 1 (text/plain, inline)]
Hi Juri,

I recently came across a regression of performance in Emacs for describe bindings, which I have reported as bug#45379. After bisection, the offending seems to be a commit a649034336 you pushed in November 2020, to fix bug#5423. Since I have received no reply after bug#45379 was reported (more than 2 weeks), I guess it's better to contact you and cc every participants of bug#5423. I am including the description of the bug report here for your convenience.

> `describe-buffer-bindings` has become significantly slower since the
following commit

a649034336 * bad Don't show key ranges if shadowed by different commands

This also makes `describe-bindings` and anything depending on it hardly
usable. For me, it takes about 2 seconds on vanilla Emacs in an org-mode
buffer, and a few minutes on my Emacs configuration (was almost instant
before the offending commit).
> 

Sheng Yang(杨圣), PhD candidate
Computer Science Department
University of Maryland, College Park
E-mail: styang <at> fastmail.com
E-mail (old but still used): yangsheng6810 <at> gmail.com

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Fri, 08 Jan 2021 17:01:02 GMT) Full text and rfc822 format available.

Message #11 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Sheng Yang <styang <at> fastmail.com>, Juri Linkov <juri <at> linkov.net>
Cc: martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>,
 45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Stephen Berman <stephen.berman <at> gmx.net>
Subject: Re: 28.0.50; Degraded Performance of describe-buffer-bindings
Date: Fri, 8 Jan 2021 11:00:08 -0600
"Sheng Yang" <styang <at> fastmail.com> writes:

> Since I have received no reply after bug#45379 was reported (more than
> 2 weeks), I guess it's better to contact you and cc every participants
> of bug#5423.

Thanks for the ping.  I am working on a fix that I'm hoping to find the
time to finish up soon, possibly already this weekend.




Added tag(s) confirmed. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 08 Jan 2021 17:01:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Fri, 08 Jan 2021 17:09:02 GMT) Full text and rfc822 format available.

Message #16 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Sheng Yang <styang <at> fastmail.com>, Juri Linkov <juri <at> linkov.net>
Cc: martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>,
 45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Stephen Berman <stephen.berman <at> gmx.net>
Subject: Re: 28.0.50; Degraded Performance of describe-buffer-bindings
Date: Fri, 8 Jan 2021 11:08:14 -0600
"Sheng Yang" <styang <at> fastmail.com> writes:

> Hi Juri,
>
> I recently came across a regression of performance in Emacs for
> describe bindings, which I have reported as bug#45379. After
> bisection, the offending seems to be a commit a649034336 you pushed in
> November 2020, to fix bug#5423. [...]
>
> a649034336 * bad Don't show key ranges if shadowed by different commands

BTW, the offending commit is not Juri's.  It is mine:

    Author: Stefan Kangas <stefan <at> marxist.se>
    Date:   Fri Nov 13 15:28:29 2020 +0100

        Don't show key ranges if shadowed by different commands

Thanks for the bug report!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Thu, 04 Feb 2021 15:44:01 GMT) Full text and rfc822 format available.

Message #19 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: "Sheng Yang" <styang <at> fastmail.com>
To: "Stefan Kangas" <stefan <at> marxist.se>, "Juri Linkov" <juri <at> linkov.net>
Cc: martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>,
 45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Stephen Berman <stephen.berman <at> gmx.net>
Subject: Re: 28.0.50; Degraded Performance of describe-buffer-bindings
Date: Thu, 04 Feb 2021 09:43:25 -0600
[Message part 1 (text/plain, inline)]
Any update on this bug? 

On Fri, Jan 8, 2021, at 11:08, Stefan Kangas wrote:
> "Sheng Yang" <styang <at> fastmail.com> writes:
> 
> > Hi Juri,
> >
> > I recently came across a regression of performance in Emacs for
> > describe bindings, which I have reported as bug#45379. After
> > bisection, the offending seems to be a commit a649034336 you pushed in
> > November 2020, to fix bug#5423. [...]
> >
> > a649034336 * bad Don't show key ranges if shadowed by different commands
> 
> BTW, the offending commit is not Juri's.  It is mine:
> 
>     Author: Stefan Kangas <stefan <at> marxist.se>
>     Date:   Fri Nov 13 15:28:29 2020 +0100
> 
>         Don't show key ranges if shadowed by different commands
> 
> Thanks for the bug report!
> 

Sheng Yang(杨圣), PhD candidate
Computer Science Department
University of Maryland, College Park
E-mail: styang <at> fastmail.com
E-mail (old but still used): yangsheng6810 <at> gmail.com

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 06 Mar 2021 04:45:01 GMT) Full text and rfc822 format available.

Message #22 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Sheng Yang <styang <at> fastmail.com>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, Juri Linkov <juri <at> linkov.net>,
 martin rudalics <rudalics <at> gmx.at>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Eli Zaretskii <eliz <at> gnu.org>, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Fri, 5 Mar 2021 20:44:33 -0800
[Message part 1 (text/plain, inline)]
tags 45379 + patch
thanks

Stefan Kangas <stefan <at> marxist.se> writes:

> "Sheng Yang" <styang <at> fastmail.com> writes:
>
>> Hi Juri,
>>
>> I recently came across a regression of performance in Emacs for
>> describe bindings, which I have reported as bug#45379. After
>> bisection, the offending seems to be a commit a649034336 you pushed in
>> November 2020, to fix bug#5423. [...]
>>
>> a649034336 * bad Don't show key ranges if shadowed by different commands
>
> BTW, the offending commit is not Juri's.  It is mine:
>
>     Author: Stefan Kangas <stefan <at> marxist.se>
>     Date:   Fri Nov 13 15:28:29 2020 +0100
>
>         Don't show key ranges if shadowed by different commands

Please try the attached patch and see that it fixes this performance
regression.

It turns out that we were doing unnecessary looping due to the above
mentioned commit.  While working on this, I also found that we can get
rid of an unnecessary call to char_table_ref_and_range, which should
make this function run even faster.

I'm also copying in Kenichi Handa, who was the last to touch this code.
Handa-san, please let us know if you have any comments on this patch.
Thanks in advance.
[0001-Fix-describe-buffer-bindings-performance-regression.patch (text/x-diff, attachment)]

Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sat, 06 Mar 2021 04:45:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 06 Mar 2021 08:16:02 GMT) Full text and rfc822 format available.

Message #27 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>, Kenichi Handa <handa <at> gnu.org>
Cc: juri <at> linkov.net, styang <at> fastmail.com, stephen.berman <at> gmx.net,
 rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sat, 06 Mar 2021 10:15:16 +0200
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Fri, 5 Mar 2021 20:44:33 -0800
> Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> 	Stephen Berman <stephen.berman <at> gmx.net>
> 
> It turns out that we were doing unnecessary looping due to the above
> mentioned commit.  While working on this, I also found that we can get
> rid of an unnecessary call to char_table_ref_and_range, which should
> make this function run even faster.

I'm not sure I understand the reasons for each of the changes here.
char-tables are a tricky data structure, so I'd like to make sure this
change doesn't make our code subtly incorrect.

So could you please walk us through the proposed changes, adding
explanations for each part as you go?

(And what do char-tables have to do with describing key bindings,
btw?)

> I'm also copying in Kenichi Handa, who was the last to touch this code.
> Handa-san, please let us know if you have any comments on this patch.
> Thanks in advance.

AFAICT, you didn't CC Kenichi; I have now added him to the discussion.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sun, 07 Mar 2021 01:44:01 GMT) Full text and rfc822 format available.

Message #30 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: handa <handa <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: handa <at> gnu.org, styang <at> fastmail.com, stephen.berman <at> gmx.net,
 stefan <at> marxist.se, juri <at> linkov.net, rudalics <at> gmx.at, monnier <at> iro.umontreal.ca,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50; Degraded Performance of
 describe-buffer-bindings
Date: Sun, 07 Mar 2021 10:42:39 +0900
In article <83v9a4wve3.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:

> > From: Stefan Kangas <stefan <at> marxist.se>
> > Date: Fri, 5 Mar 2021 20:44:33 -0800
> > Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> > 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> > 	Stephen Berman <stephen.berman <at> gmx.net>
> > 
> > It turns out that we were doing unnecessary looping due to the above
> > mentioned commit.

Could you show me what is "the above mentioned commit"?

> >  While working on this, I also found that we can get
> > rid of an unnecessary call to char_table_ref_and_range, which should
> > make this function run even faster.

Is the patch for the above improvement the one included in the file
0001-Fix-describe-buffer-bindings-performance-regression.patch?

> > I'm also copying in Kenichi Handa, who was the last to touch this code.
> > Handa-san, please let us know if you have any comments on this patch.
> > Thanks in advance.

> AFAICT, you didn't CC Kenichi; I have now added him to the discussion.

It was more than 10 years ago that I last read keymap.c, and since then,
the code has been changed a lot.  It will take some time to understand
the latest code.

---
K. Handa
handa <at> gnu.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sun, 07 Mar 2021 06:16:01 GMT) Full text and rfc822 format available.

Message #33 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: handa <handa <at> gnu.org>
Cc: handa <at> gnu.org, styang <at> fastmail.com, stephen.berman <at> gmx.net,
 stefan <at> marxist.se, juri <at> linkov.net, rudalics <at> gmx.at, monnier <at> iro.umontreal.ca,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50; Degraded Performance of
 describe-buffer-bindings
Date: Sun, 07 Mar 2021 08:15:10 +0200
> From: handa <handa <at> gnu.org>
> Cc: stefan <at> marxist.se, styang <at> fastmail.com, juri <at> linkov.net, rudalics <at> gmx.at,
> 	45379 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca,
> 	stephen.berman <at> gmx.net, handa <at> gnu.org
> Date: Sun, 07 Mar 2021 10:42:39 +0900
> 
> In article <83v9a4wve3.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > > From: Stefan Kangas <stefan <at> marxist.se>
> > > Date: Fri, 5 Mar 2021 20:44:33 -0800
> > > Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> > > 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> > > 	Stephen Berman <stephen.berman <at> gmx.net>
> > > 
> > > It turns out that we were doing unnecessary looping due to the above
> > > mentioned commit.
> 
> Could you show me what is "the above mentioned commit"?

This one, I guess:

> commit a6490343366f2b2331a91dcb693effb3a9dd78f5
> Author:     Stefan Kangas <stefan <at> marxist.se>
> AuthorDate: Fri Nov 13 15:28:29 2020 +0100
> Commit:     Stefan Kangas <stefan <at> marxist.se>
> CommitDate: Sun Nov 22 02:45:03 2020 +0100
> 
>     Don't show key ranges if shadowed by different commands
> 
>     * src/keymap.c (describe_vector): Make sure found consecutive keys
>     are either not shadowed or, if they are, that they are shadowed by
>     the same command.  (Bug#9293)
>     * test/src/keymap-tests.el
>     (help--describe-vector/bug-9293-one-shadowed-in-range): New test.

> > >  While working on this, I also found that we can get
> > > rid of an unnecessary call to char_table_ref_and_range, which should
> > > make this function run even faster.
> 
> Is the patch for the above improvement the one included in the file
> 0001-Fix-describe-buffer-bindings-performance-regression.patch?

Yes, it is.

> > > I'm also copying in Kenichi Handa, who was the last to touch this code.
> > > Handa-san, please let us know if you have any comments on this patch.
> > > Thanks in advance.
> 
> > AFAICT, you didn't CC Kenichi; I have now added him to the discussion.
> 
> It was more than 10 years ago that I last read keymap.c, and since then,
> the code has been changed a lot.  It will take some time to understand
> the latest code.

Thanks in advance.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sun, 07 Mar 2021 08:13:01 GMT) Full text and rfc822 format available.

Message #36 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>, Kenichi Handa <handa <at> gnu.org>
Cc: juri <at> linkov.net, styang <at> fastmail.com, stephen.berman <at> gmx.net,
 rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sun, 7 Mar 2021 03:12:17 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:

>> It turns out that we were doing unnecessary looping due to the above
>> mentioned commit.  While working on this, I also found that we can get
>> rid of an unnecessary call to char_table_ref_and_range, which should
>> make this function run even faster.
>
> I'm not sure I understand the reasons for each of the changes here.
> char-tables are a tricky data structure, so I'd like to make sure this
> change doesn't make our code subtly incorrect.

Thanks.

I have been struggling to come up with good unit tests, so any ideas
about that would also be very welcome.

> So could you please walk us through the proposed changes, adding
> explanations for each part as you go?

Yes.  Please allow for at least a couple of days to write this up.

> (And what do char-tables have to do with describing key bindings,
> btw?)

Full keymaps are char-tables, while sparse keymaps are just lists.

The call stack looks like this:

Fdescribe_buffer_bindings [keymap.c]
-> describe-map-tree      [help.el]
-> describe-map
-> Fhelp__describe_vector [keymap.c]
-> describe_vector




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sun, 07 Mar 2021 08:39:01 GMT) Full text and rfc822 format available.

Message #39 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: styang <at> fastmail.com, rudalics <at> gmx.at, stephen.berman <at> gmx.net,
 juri <at> linkov.net, handa <at> gnu.org, monnier <at> iro.umontreal.ca,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sun, 07 Mar 2021 10:38:19 +0200
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Sun, 7 Mar 2021 03:12:17 -0500
> Cc: styang <at> fastmail.com, juri <at> linkov.net, rudalics <at> gmx.at, 
> 	45379 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca, stephen.berman <at> gmx.net
> 
> > So could you please walk us through the proposed changes, adding
> > explanations for each part as you go?
> 
> Yes.  Please allow for at least a couple of days to write this up.

Sure.  There's no rush, please take your time.

> > (And what do char-tables have to do with describing key bindings,
> > btw?)
> 
> Full keymaps are char-tables, while sparse keymaps are just lists.
> 
> The call stack looks like this:
> 
> Fdescribe_buffer_bindings [keymap.c]
> -> describe-map-tree      [help.el]
> -> describe-map
> -> Fhelp__describe_vector [keymap.c]
> -> describe_vector

Got it, thanks.




Merged 45379 47494. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 30 Mar 2021 06:59:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Tue, 30 Mar 2021 07:02:02 GMT) Full text and rfc822 format available.

Message #44 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kenichi Handa <handa <at> gnu.org>
Cc: stephen.berman <at> gmx.net, stefan <at> marxist.se, juri <at> linkov.net, handa <at> gnu.org,
 styang <at> fastmail.com, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Tue, 30 Mar 2021 10:01:19 +0300
Ping!  Kenichi, could you please help us with this issue?

> Date: Sun, 07 Mar 2021 08:15:10 +0200
> From: Eli Zaretskii <eliz <at> gnu.org>
> Cc: stephen.berman <at> gmx.net, 45379 <at> debbugs.gnu.org, stefan <at> marxist.se,
>  juri <at> linkov.net, handa <at> gnu.org, monnier <at> iro.umontreal.ca, styang <at> fastmail.com
> 
> > From: handa <handa <at> gnu.org>
> > Cc: stefan <at> marxist.se, styang <at> fastmail.com, juri <at> linkov.net, rudalics <at> gmx.at,
> > 	45379 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca,
> > 	stephen.berman <at> gmx.net, handa <at> gnu.org
> > Date: Sun, 07 Mar 2021 10:42:39 +0900
> > 
> > In article <83v9a4wve3.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:
> > 
> > > > From: Stefan Kangas <stefan <at> marxist.se>
> > > > Date: Fri, 5 Mar 2021 20:44:33 -0800
> > > > Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> > > > 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> > > > 	Stephen Berman <stephen.berman <at> gmx.net>
> > > > 
> > > > It turns out that we were doing unnecessary looping due to the above
> > > > mentioned commit.
> > 
> > Could you show me what is "the above mentioned commit"?
> 
> This one, I guess:
> 
> > commit a6490343366f2b2331a91dcb693effb3a9dd78f5
> > Author:     Stefan Kangas <stefan <at> marxist.se>
> > AuthorDate: Fri Nov 13 15:28:29 2020 +0100
> > Commit:     Stefan Kangas <stefan <at> marxist.se>
> > CommitDate: Sun Nov 22 02:45:03 2020 +0100
> > 
> >     Don't show key ranges if shadowed by different commands
> > 
> >     * src/keymap.c (describe_vector): Make sure found consecutive keys
> >     are either not shadowed or, if they are, that they are shadowed by
> >     the same command.  (Bug#9293)
> >     * test/src/keymap-tests.el
> >     (help--describe-vector/bug-9293-one-shadowed-in-range): New test.
> 
> > > >  While working on this, I also found that we can get
> > > > rid of an unnecessary call to char_table_ref_and_range, which should
> > > > make this function run even faster.
> > 
> > Is the patch for the above improvement the one included in the file
> > 0001-Fix-describe-buffer-bindings-performance-regression.patch?
> 
> Yes, it is.
> 
> > > > I'm also copying in Kenichi Handa, who was the last to touch this code.
> > > > Handa-san, please let us know if you have any comments on this patch.
> > > > Thanks in advance.
> > 
> > > AFAICT, you didn't CC Kenichi; I have now added him to the discussion.
> > 
> > It was more than 10 years ago that I last read keymap.c, and since then,
> > the code has been changed a lot.  It will take some time to understand
> > the latest code.
> 
> Thanks in advance.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Thu, 01 Apr 2021 15:07:01 GMT) Full text and rfc822 format available.

Message #47 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: handa <handa <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: stephen.berman <at> gmx.net, stefan <at> marxist.se, juri <at> linkov.net,
 styang <at> fastmail.com, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50; Degraded Performance of
 describe-buffer-bindings
Date: Fri, 02 Apr 2021 00:06:40 +0900
In article <838s65ktvk.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:

> > > Is the patch for the above improvement the one included in the file
> > > 0001-Fix-describe-buffer-bindings-performance-regression.patch?
> > 
> > Yes, it is.

It seems that the main intention of that patch is to avoid unnecessary
call of char_table_ref_and_range introduced by the commit below:

> >     Don't show key ranges if shadowed by different commands
> > 
> >     * src/keymap.c (describe_vector): Make sure found consecutive keys
> >     are either not shadowed or, if they are, that they are shadowed by
> >     the same command.  (Bug#9293)

In describe_vector, if VECTOR is a char-table, char_table_ref_and_range
is already called at the fairly beginning of the main loop.  So, we do
not have to call it again, and thus, I think the patch is doing the
correct thing.

But, I don't know whether the following part in the patch is correct or
not.

+	  /* Ignore `self-insert-command' for performance.  */
+	  && !EQ (definition, Qself_insert_command))

---
K. Handa
handa <at> gnu.org




Merged 45379 47494 47565. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Fri, 02 Apr 2021 14:57:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Wed, 14 Apr 2021 03:07:01 GMT) Full text and rfc822 format available.

Message #52 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: "Sheng Yang" <styang <at> fastmail.com>
To: handa <handa <at> gnu.org>, "Eli Zaretskii" <eliz <at> gnu.org>
Cc: 45379 <at> debbugs.gnu.org, Stephen Berman <stephen.berman <at> gmx.net>,
 Stefan Kangas <stefan <at> marxist.se>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#45379: 28.0.50;
  Degraded Performance of describe-buffer-bindings
Date: Tue, 13 Apr 2021 22:06:29 -0500
[Message part 1 (text/plain, inline)]
Any update on this? Having been using the patch for a few weeks now, seems fine for me.

On Thu, Apr 1, 2021, at 10:06, handa wrote:
> In article <838s65ktvk.fsf <at> gnu.org <mailto:838s65ktvk.fsf%40gnu.org>>, Eli Zaretskii <eliz <at> gnu.org <mailto:eliz%40gnu.org>> writes:
> 
> > > > Is the patch for the above improvement the one included in the file
> > > > 0001-Fix-describe-buffer-bindings-performance-regression.patch?
> > > 
> > > Yes, it is.
> 
> It seems that the main intention of that patch is to avoid unnecessary
> call of char_table_ref_and_range introduced by the commit below:
> 
> > >     Don't show key ranges if shadowed by different commands
> > > 
> > >     * src/keymap.c (describe_vector): Make sure found consecutive keys
> > >     are either not shadowed or, if they are, that they are shadowed by
> > >     the same command.  (Bug#9293)
> 
> In describe_vector, if VECTOR is a char-table, char_table_ref_and_range
> is already called at the fairly beginning of the main loop.  So, we do
> not have to call it again, and thus, I think the patch is doing the
> correct thing.
> 
> But, I don't know whether the following part in the patch is correct or
> not.
> 
> +   /* Ignore `self-insert-command' for performance.  */
> +   && !EQ (definition, Qself_insert_command))
> 
> ---
> K. Handa
> handa <at> gnu.org <mailto:handa%40gnu.org>
> 

Sheng Yang(杨圣), PhD
Computer Science Department
University of Maryland, College Park
E-mail: styang <at> fastmail.com
E-mail (old but still used): yangsheng6810 <at> gmail.com

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Tue, 04 May 2021 23:32:02 GMT) Full text and rfc822 format available.

Message #55 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Sheng Yang <styang <at> fastmail.com>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, Kenichi Handa <handa <at> gnu.org>,
 Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Eli Zaretskii <eliz <at> gnu.org>,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Tue, 4 May 2021 18:31:10 -0500
I finally had time/energy to look into this again!  Sorry for taking
more time than expected.

handa <handa <at> gnu.org> writes:

> In article <838s65ktvk.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:
>
>> > > Is the patch for the above improvement the one included in the file
>> > > 0001-Fix-describe-buffer-bindings-performance-regression.patch?
>> >
>> > Yes, it is.
>
> It seems that the main intention of that patch is to avoid unnecessary
> call of char_table_ref_and_range introduced by the commit below:
>
>> >     Don't show key ranges if shadowed by different commands
>> >
>> >     * src/keymap.c (describe_vector): Make sure found consecutive keys
>> >     are either not shadowed or, if they are, that they are shadowed by
>> >     the same command.  (Bug#9293)
>
> In describe_vector, if VECTOR is a char-table, char_table_ref_and_range
> is already called at the fairly beginning of the main loop.  So, we do
> not have to call it again, and thus, I think the patch is doing the
> correct thing.

Yes, this is all correct.

> But, I don't know whether the following part in the patch is correct or
> not.
>
> +	  /* Ignore `self-insert-command' for performance.  */
> +	  && !EQ (definition, Qself_insert_command))

(This is explained below.)

Eli Zaretskii <eliz <at> gnu.org> writes:

> I'm not sure I understand the reasons for each of the changes here.
> char-tables are a tricky data structure, so I'd like to make sure this
> change doesn't make our code subtly incorrect.
>
> So could you please walk us through the proposed changes, adding
> explanations for each part as you go?

This code is a bit complicated, so please bare with me if I am going
into too much detail.  BTW, note that I have also carried out a lot of
testing to see that my change does the same thing as before, only faster
(unfortunately it has been harder to come up with useful automated tests
beyond the ones we already have).

First, it might help to think of this as consisting of two parts:

1. A cleanup of the boundary condition check.  It is simply to make this
   code a bit more clear and easier to follow.

2. The actual bug fix for the performance bug.

I put a divider in between these two parts to make things hopefully a
bit more clear.

Stefan Kangas <stefan <at> marxist.se> writes:

> From f95c75f1112c1aae0bd06a6753b60ce8a591d6e2 Mon Sep 17 00:00:00 2001
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Sat, 6 Mar 2021 05:32:32 +0100
> Subject: [PATCH] Fix describe-buffer-bindings performance regression
>
> * src/keymap.c (describe_vector): Improve char-table performance by
> removing an unnecessary loop.  (Bug#45379)
> (syms_of_keymap) <Qself_insert_command>: New DEFSYM.
> ---
>  src/keymap.c | 47 +++++++++++++++++++----------------------------
>  1 file changed, 19 insertions(+), 28 deletions(-)
>
> diff --git a/src/keymap.c b/src/keymap.c
> index 782931fadf..c70df98a6e 100644
> --- a/src/keymap.c
> +++ b/src/keymap.c
> @@ -2920,7 +2920,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
>    Lisp_Object suppress = Qnil;
>    bool first = true;
>    /* Range of elements to be handled.  */
> -  int from, to, stop;
> +  int to, stop;
>
>    if (!keymap_p)
>      {
> @@ -2940,32 +2940,33 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
>    if (partial)
>      suppress = intern ("suppress-keymap");
>
> -  from = 0;

The "from" variable is initialized to 0 below and is redundant.  So it
is replaced with the constant 0, which I think makes the intention of
this code more clear.  IOW, this is just a cleanup.

> +  /* If VECTOR is a char-table, we had better put a boundary
> +     between normal characters (-#x3FFF7F) and 8-bit characters
> +     (#x3FFF80-).  */
>    if (CHAR_TABLE_P (vector))
>      stop = MAX_5_BYTE_CHAR + 1, to = MAX_CHAR + 1;
>    else
>      stop = to = ASIZE (vector);

The above puts a "boundary" that we need to handle below by stopping
(skipping to the next range) when we reach "stop".

We must end the loop altogether only when we reach "to".

Note that for char tables stop != to, otherwise stop == to

>
> -  for (int i = from; ; i++)
> +  for (int i = 0; i < to; i++)
>      {

Here we stop when we reach "to", which is what we intend.

The "from" mentioned above is also here replaced with constant 0.

>        bool this_shadowed = false;
>        Lisp_Object shadowed_by = Qnil;
> -      int range_beg, range_end;
> +      int range_beg;

[range_end is now unused and so removed.]

>        Lisp_Object val, tem2;
>
>        maybe_quit ();
>
> -      if (i == stop)
> -	{
> -	  if (i == to)
> -	    break;

This is a bit complicated to follow, so I have cleaned it up.

What happens here is that we exit the loop if "i == to".

The rest is to handle the above "boundary".  We have two cases:

1. If this is not a char table:

    i == stop  implies that  i == to

   (The loop will always end here.)

2. If this is a char table:

   i == stop   does not imply that   i == to

  a) The loop will end if

   i == stop  ∧  i == to

   (This can never be the case the first time we reach this, see above.
   We must first have reached the 2b) immediately below in a previous
   iteration.)

> -	  stop = to;
> -	}
> -

  b) Otherwise, if "i == stop ∧ i != to", we set "stop = to"

   (Again, only when this has happened can we reach 2a.)

But this is all removed, so the 2b) action is moved here:

>        int starting_i = i;
>
>        if (CHAR_TABLE_P (vector))
>  	{
> +	  /* Take care of the boundary.  */
> +	  if (i == stop)
> +	    stop = to;

IOW, here "i != to", but "i == stop" so we set "stop = to".  Just as
before.

Thus, the boundary condition is handled.

————————————– End part 1, performance bug fix follows:

> +	  /* Find the first element between i and stop - 1.  Put its
> +	     index in i.  */
>  	  range_beg = i;
>  	  i = stop - 1;
>  	  val = char_table_ref_and_range (vector, range_beg, &range_beg, &i);
                ^^^^^^^^^^^^^^^^^^^^^^^^

First call to "char_table_ref_and_range".

This puts the correct values in the "range_beg" variables and "i", where
"range_beg" is the start of the range and "i" is the last item in the
range that has the same value.

This is followed by:

>	}
>      else
>	val = AREF (vector, i);
>      Lisp_Object definition = get_keyelt (val, 0);
>
>      if (NILP (definition)) continue;

IOW, we skip it if it is not defined.

This is important to see why we can remove the next part.

> @@ -3024,21 +3025,8 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
>        insert1 (Fkey_description (kludge, prefix));
>
>        /* Find all consecutive characters or rows that have the same
> -	 definition.  But, if VECTOR is a char-table, we had better
> -	 put a boundary between normal characters (-#x3FFF7F) and
> -	 8-bit characters (#x3FFF80-).  */
> -      if (CHAR_TABLE_P (vector))
> -	{
> -	  while (i + 1 < stop
> -		 && (range_beg = i + 1, range_end = stop - 1,
> -		   val = char_table_ref_and_range (vector, range_beg,
> -						   &range_beg, &range_end),
                         ^^^^^^^^^^^^^^^^^^^^^^^^

This second call simply tries to call up a *second* range within the
same iteration.  This is to "put a boundary" (commit bed6185fecbb), but
it is crucial to note this is _already handled_ above.

This is therefore superfluous, as we can see from what happens next:

> -		   tem2 = get_keyelt (val, 0),
> -		   !NILP (tem2))
> -		 && !NILP (Fequal (tem2, definition)))
> -	    i = range_end;

This is all just to continue advancing down the char table until we find
something.  Again, note that above we already do exactly the same thing,
so doing it here as well is superfluous.

I.e. compare these statements to the lines above, specifically:

    Lisp_Object definition = get_keyelt (val, 0);
    if (NILP (definition)) continue;

Pay particular attention to the variables i, range_beg, and range_end.

> -	}
> -      else
> +	 definition.  */
> +      if (!CHAR_TABLE_P (vector))
>  	while (i + 1 < stop
>  	       && (tem2 = get_keyelt (AREF (vector, i + 1), 0),
>  		   !NILP (tem2))

(Note that there is no change if this is not a char-table.)

> @@ -3047,10 +3035,12 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
>
>        /* Make sure found consecutive keys are either not shadowed or,
>  	 if they are, that they are shadowed by the same command.  */
> -      if (CHAR_TABLE_P (vector) && i != starting_i)
> +      if (CHAR_TABLE_P (vector) && i != starting_i
> +	  /* Ignore `self-insert-command' for performance.  */
> +	  && !EQ (definition, Qself_insert_command))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To see if the shadowing is the same for an entire range, we need to run
shadow_lookup() for *once for each character* in that range to see if
they are shadowed.  This is expensive.

One observation is that we often have *very long* ranges of characters
where the value is "self-insert-command", as in:

    (lookup-key global-map "文")

This is because a char-table will cover the range of all valid character
codes.  [Note again that we use a char-table only if the keymap is
defined with `make-keymap' (as opposed to `make-sparse-keymap', which is
just a list)]

Let's just assume that it is unlikely that there is any shadowing going
on for all of these self-inserting keys.  If there is shadowing going
on, we are probably not looking at a keymap where we have the default
value is set to self-insert-command.

So we basically say here: let's just not care about
`self-insert-command' and skip the check.  Yes, we will in theory not
get a perfect result, as there will be some cases where we miss the
shadowing.  OTOH, we are sure to have something that is not very slow.
(And in any case, I don't know of any examples where this will fail, and
if they exist we will in any case already be doing better than Emacs 27,
as this entire check is new in Emacs 28.)

>  	{
>  	  Lisp_Object key = make_nil_vector (1);
> -	  for (int j = starting_i + 1; j <= i; j++)
> +	  for (int j = range_beg + 1; j <= i; j++)
                       ^^^^^^^^^^

("range_beg" is the start of the actual range here, previously it was
starting_i due to the second call to char_table_ref_and_range.)

>  	    {
>  	      ASET (key, 0, make_fixnum (j));
>  	      Lisp_Object tem = shadow_lookup (shadow, key, Qt, 0);
> @@ -3109,6 +3099,7 @@ syms_of_keymap (void)
>    DEFSYM (Qdescribe_map_tree, "describe-map-tree");
>
>    DEFSYM (Qkeymap_canonicalize, "keymap-canonicalize");
> +  DEFSYM (Qself_insert_command, "self-insert-command");
>
>    /* Now we are ready to set up this property, so we can
>       create char tables.  */
> --
> 2.30.1

Phew!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Thu, 06 May 2021 10:13:02 GMT) Full text and rfc822 format available.

Message #58 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: juri <at> linkov.net, styang <at> fastmail.com, handa <at> gnu.org, stephen.berman <at> gmx.net,
 rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Thu, 06 May 2021 13:11:37 +0300
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Tue, 4 May 2021 18:31:10 -0500
> Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> 	Stephen Berman <stephen.berman <at> gmx.net>, Kenichi Handa <handa <at> gnu.org>
> 
> I finally had time/energy to look into this again!  Sorry for taking
> more time than expected.

Thanks for your time and efforts.  I will review this as soon as I
have enough time to do so.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Thu, 13 May 2021 10:11:02 GMT) Full text and rfc822 format available.

Message #61 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: juri <at> linkov.net, styang <at> fastmail.com, handa <at> gnu.org, stephen.berman <at> gmx.net,
 rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Thu, 13 May 2021 13:10:38 +0300
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Tue, 4 May 2021 18:31:10 -0500
> Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> 	Stephen Berman <stephen.berman <at> gmx.net>, Kenichi Handa <handa <at> gnu.org>
> 
> I finally had time/energy to look into this again!  Sorry for taking
> more time than expected.

Thanks.  And I have finally found enough free time to review this.  A
couple of comments below, and then I'm okay with installing these
changes.

> > But, I don't know whether the following part in the patch is correct or
> > not.
> >
> > +	  /* Ignore `self-insert-command' for performance.  */
> > +	  && !EQ (definition, Qself_insert_command))
> 
> (This is explained below.)

And I have a comment for that explanation.

> >        Lisp_Object val, tem2;
> >
> >        maybe_quit ();
> >
> > -      if (i == stop)
> > -	{
> > -	  if (i == to)
> > -	    break;
> 
> This is a bit complicated to follow, so I have cleaned it up.

I don't see the modified code regarding this to/stop issue as more
clear than the original one.  In both cases there's a special test
which then sets stop = to.  I needed to read the new code several
times to convince myself we perform the same amount of run-time tests
inside the loop.  So I'd prefer to leave this nit alone, as it was in
the original code.  If you find that somewhat unclear, how about
adding a comment there explaining whatever it was unclear to you when
you first read that?

> > @@ -3047,10 +3035,12 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
> >
> >        /* Make sure found consecutive keys are either not shadowed or,
> >  	 if they are, that they are shadowed by the same command.  */
> > -      if (CHAR_TABLE_P (vector) && i != starting_i)
> > +      if (CHAR_TABLE_P (vector) && i != starting_i
> > +	  /* Ignore `self-insert-command' for performance.  */
> > +	  && !EQ (definition, Qself_insert_command))
>               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> To see if the shadowing is the same for an entire range, we need to run
> shadow_lookup() for *once for each character* in that range to see if
> they are shadowed.  This is expensive.
> 
> One observation is that we often have *very long* ranges of characters
> where the value is "self-insert-command", as in:
> 
>     (lookup-key global-map "文")
> 
> This is because a char-table will cover the range of all valid character
> codes.  [Note again that we use a char-table only if the keymap is
> defined with `make-keymap' (as opposed to `make-sparse-keymap', which is
> just a list)]
> 
> Let's just assume that it is unlikely that there is any shadowing going
> on for all of these self-inserting keys.  If there is shadowing going
> on, we are probably not looking at a keymap where we have the default
> value is set to self-insert-command.
> 
> So we basically say here: let's just not care about
> `self-insert-command' and skip the check.  Yes, we will in theory not
> get a perfect result, as there will be some cases where we miss the
> shadowing.  OTOH, we are sure to have something that is not very slow.
> (And in any case, I don't know of any examples where this will fail, and
> if they exist we will in any case already be doing better than Emacs 27,
> as this entire check is new in Emacs 28.)

To tell the truth, I'm a bit worried by this "assumption", and so was
Handa-san.  This part of the change looks to me like simply ignoring a
legitimate situation which we previously supported, and now will not,
for the sole reason that the test is slow.  Who can tell us what this
could cause in some code somewhere in the community?  "Don't know any
examples where it will fail" is not very assuring, IMO.

Is this part of the change what speeds up describe-buffer-bindings?
Or is this just part of the speedup?  In the latter case, how much
faster will describe-buffer-bindings become without this
"optimization"?  And in the former case, I'd prefer to have this
"optimization" controllable by some variable, which we could then use
in the future as a "fire escape" if someone comes up with a use case
where the code you want to remove is indeed needed.

Alternatively, how about making the "Don't show key ranges if shadowed
by different commands" feature, which triggered this regression,
optional, by default off?  Then people who want it could be warned
that it might slow down describe-buffer-bindings, and will have to
decide whether they care enough about the speed to have the feature
turned on.

In any case, at least some of this explanation should be in comments
to the code, no matter whether we leave it alone or bypass it
conditionally.  If we introduce a variable to control this, some of
this should be in the doc string of that variable.

Thanks again for working on this, and sorry it took me so long to get
to review it.




Merged 45379 47494 47565 48812. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 03 Jun 2021 17:16:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 26 Jun 2021 21:52:02 GMT) Full text and rfc822 format available.

Message #66 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: "Sheng Yang" <styang <at> fastmail.com>
To: "Eli Zaretskii" <eliz <at> gnu.org>, "Stefan Kangas" <stefan <at> marxist.se>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, martin rudalics <rudalics <at> gmx.at>,
 Juri Linkov <juri <at> linkov.net>, handa <handa <at> gnu.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
  Degraded Performance of describe-buffer-bindings
Date: Sat, 26 Jun 2021 16:51:19 -0500
[Message part 1 (text/plain, inline)]
A month has passed, any update on this? I see someone also reported this issue on the mailing list today.


Sheng Yang(杨圣), PhD
Computer Science Department
University of Maryland, College Park
E-mail: styang <at> fastmail.com
E-mail (old but still used): yangsheng6810 <at> gmail.com

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sun, 27 Jun 2021 05:57:02 GMT) Full text and rfc822 format available.

Message #69 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Sheng Yang" <styang <at> fastmail.com>
Cc: stephen.berman <at> gmx.net, handa <at> gnu.org, stefan <at> marxist.se, juri <at> linkov.net,
 rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sun, 27 Jun 2021 08:56:09 +0300
> Date: Sat, 26 Jun 2021 16:51:19 -0500
> From: "Sheng Yang" <styang <at> fastmail.com>
> Cc: "Juri Linkov" <juri <at> linkov.net>, "martin rudalics" <rudalics <at> gmx.at>,
>  45379 <at> debbugs.gnu.org, "Stefan Monnier" <monnier <at> iro.umontreal.ca>,
>  "Stephen Berman" <stephen.berman <at> gmx.net>, handa <handa <at> gnu.org>
> 
> A month has passed, any update on this? I see someone also reported this issue on the mailing list today.

Not yet, sorry.  I guess Stefan has other things on his plate.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Tue, 07 Sep 2021 18:54:02 GMT) Full text and rfc822 format available.

Message #72 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: stefan <at> marxist.se
Cc: stephen.berman <at> gmx.net, rudalics <at> gmx.at, 45379 <at> debbugs.gnu.org,
 juri <at> linkov.net, handa <at> gnu.org, monnier <at> iro.umontreal.ca, styang <at> fastmail.com
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Tue, 07 Sep 2021 21:53:16 +0300
Ping!  Stefan, can we please resolve this issue?  I think we cannot
release Emacs 28 without fixing this regression.

TIA

> Date: Thu, 13 May 2021 13:10:38 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> Cc: juri <at> linkov.net, styang <at> fastmail.com, handa <at> gnu.org, stephen.berman <at> gmx.net,
>  rudalics <at> gmx.at, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
> 
> > From: Stefan Kangas <stefan <at> marxist.se>
> > Date: Tue, 4 May 2021 18:31:10 -0500
> > Cc: Juri Linkov <juri <at> linkov.net>, martin rudalics <rudalics <at> gmx.at>, Eli Zaretskii <eliz <at> gnu.org>, 
> > 	45379 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, 
> > 	Stephen Berman <stephen.berman <at> gmx.net>, Kenichi Handa <handa <at> gnu.org>
> > 
> > I finally had time/energy to look into this again!  Sorry for taking
> > more time than expected.
> 
> Thanks.  And I have finally found enough free time to review this.  A
> couple of comments below, and then I'm okay with installing these
> changes.
> 
> > > But, I don't know whether the following part in the patch is correct or
> > > not.
> > >
> > > +	  /* Ignore `self-insert-command' for performance.  */
> > > +	  && !EQ (definition, Qself_insert_command))
> > 
> > (This is explained below.)
> 
> And I have a comment for that explanation.
> 
> > >        Lisp_Object val, tem2;
> > >
> > >        maybe_quit ();
> > >
> > > -      if (i == stop)
> > > -	{
> > > -	  if (i == to)
> > > -	    break;
> > 
> > This is a bit complicated to follow, so I have cleaned it up.
> 
> I don't see the modified code regarding this to/stop issue as more
> clear than the original one.  In both cases there's a special test
> which then sets stop = to.  I needed to read the new code several
> times to convince myself we perform the same amount of run-time tests
> inside the loop.  So I'd prefer to leave this nit alone, as it was in
> the original code.  If you find that somewhat unclear, how about
> adding a comment there explaining whatever it was unclear to you when
> you first read that?
> 
> > > @@ -3047,10 +3035,12 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
> > >
> > >        /* Make sure found consecutive keys are either not shadowed or,
> > >  	 if they are, that they are shadowed by the same command.  */
> > > -      if (CHAR_TABLE_P (vector) && i != starting_i)
> > > +      if (CHAR_TABLE_P (vector) && i != starting_i
> > > +	  /* Ignore `self-insert-command' for performance.  */
> > > +	  && !EQ (definition, Qself_insert_command))
> >               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > To see if the shadowing is the same for an entire range, we need to run
> > shadow_lookup() for *once for each character* in that range to see if
> > they are shadowed.  This is expensive.
> > 
> > One observation is that we often have *very long* ranges of characters
> > where the value is "self-insert-command", as in:
> > 
> >     (lookup-key global-map "文")
> > 
> > This is because a char-table will cover the range of all valid character
> > codes.  [Note again that we use a char-table only if the keymap is
> > defined with `make-keymap' (as opposed to `make-sparse-keymap', which is
> > just a list)]
> > 
> > Let's just assume that it is unlikely that there is any shadowing going
> > on for all of these self-inserting keys.  If there is shadowing going
> > on, we are probably not looking at a keymap where we have the default
> > value is set to self-insert-command.
> > 
> > So we basically say here: let's just not care about
> > `self-insert-command' and skip the check.  Yes, we will in theory not
> > get a perfect result, as there will be some cases where we miss the
> > shadowing.  OTOH, we are sure to have something that is not very slow.
> > (And in any case, I don't know of any examples where this will fail, and
> > if they exist we will in any case already be doing better than Emacs 27,
> > as this entire check is new in Emacs 28.)
> 
> To tell the truth, I'm a bit worried by this "assumption", and so was
> Handa-san.  This part of the change looks to me like simply ignoring a
> legitimate situation which we previously supported, and now will not,
> for the sole reason that the test is slow.  Who can tell us what this
> could cause in some code somewhere in the community?  "Don't know any
> examples where it will fail" is not very assuring, IMO.
> 
> Is this part of the change what speeds up describe-buffer-bindings?
> Or is this just part of the speedup?  In the latter case, how much
> faster will describe-buffer-bindings become without this
> "optimization"?  And in the former case, I'd prefer to have this
> "optimization" controllable by some variable, which we could then use
> in the future as a "fire escape" if someone comes up with a use case
> where the code you want to remove is indeed needed.
> 
> Alternatively, how about making the "Don't show key ranges if shadowed
> by different commands" feature, which triggered this regression,
> optional, by default off?  Then people who want it could be warned
> that it might slow down describe-buffer-bindings, and will have to
> decide whether they care enough about the speed to have the feature
> turned on.
> 
> In any case, at least some of this explanation should be in comments
> to the code, no matter whether we leave it alone or bypass it
> conditionally.  If we introduce a variable to control this, some of
> this should be in the doc string of that variable.
> 
> Thanks again for working on this, and sorry it took me so long to get
> to review it.
> 
> 
> 
> 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 18 Sep 2021 10:39:01 GMT) Full text and rfc822 format available.

Message #75 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: stefan <at> marxist.se
Cc: stephen.berman <at> gmx.net, juri <at> linkov.net, handa <at> gnu.org, styang <at> fastmail.com,
 monnier <at> iro.umontreal.ca, Lars Ingebrigtsen <larsi <at> gnus.org>,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sat, 18 Sep 2021 13:37:57 +0300
> Date: Tue, 07 Sep 2021 21:53:16 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> Cc: stephen.berman <at> gmx.net, handa <at> gnu.org, juri <at> linkov.net, styang <at> fastmail.com,
>  monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
> 
> Ping!  Stefan, can we please resolve this issue?  I think we cannot
> release Emacs 28 without fixing this regression.

Since we are close to cutting the emacs-28 release branch, and this
bug didn't see any loving care for a long time, I went ahead and fixed
this performance degradation myself, based on patches by Stefan Kangas
and their discussions in this bug report.

The feature whereby we check whether shadowing of consecutive keys is
by the same command, which AFAIU is what caused the regression, is now
optional, by default off.  There's a new variable,
'describe-bindings-check-shadowing-in-ranges', which can be used to
turn it on, and an optional value of that variable,
'ignore-self-insert', which provides some partial testing of shadowing
in these cases by trading accuracy for performance.  I also left alone
parts of the code where Stefan proposed changes of stylistic
character.

And I have a question about this whole "shadowing detection" feature.
If I repeat the recipe of bug#9293, which started all this, i.e.

  emacs -Q
  C-x C-f some-tarball-file.tar.gz RET
  M-x view-mode RET
  C-h m

then the *Help* buffer shows this at its start:

  key             binding
  ---             -------

  0 .. 9	digit-argument
  e		tar-extract  (currently shadowed by ‘View-exit’)
  f		tar-extract

  C-d		tar-flag-deleted
  RET		tar-extract
    (this binding is currently shadowed)
  C-n		tar-next-line
  C-p		tar-previous-line
  SPC		tar-next-line
    (this binding is currently shadowed)
  C		tar-copy
    (this binding is currently shadowed)

Note how the shadowing of 'e' is described with the command that
shadows it, but the shadowing of RET, SPC, and 'C' isn't.  Why is
that?  Is that a separate bug?  (This display was there even before my
changes, so I don't think the latest changes were the culprit; but for
some reason bug#9293 discussed only a small part of the *Help* display
and never looked beyond that.)

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 18 Sep 2021 12:35:02 GMT) Full text and rfc822 format available.

Message #78 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: stephen.berman <at> gmx.net, juri <at> linkov.net, handa <at> gnu.org, styang <at> fastmail.com,
 monnier <at> iro.umontreal.ca, Lars Ingebrigtsen <larsi <at> gnus.org>,
 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sat, 18 Sep 2021 05:34:08 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Date: Tue, 07 Sep 2021 21:53:16 +0300
>> From: Eli Zaretskii <eliz <at> gnu.org>
>> Cc: stephen.berman <at> gmx.net, handa <at> gnu.org, juri <at> linkov.net, styang <at> fastmail.com,
>>  monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org
>>
>> Ping!  Stefan, can we please resolve this issue?  I think we cannot
>> release Emacs 28 without fixing this regression.
>
> Since we are close to cutting the emacs-28 release branch, and this
> bug didn't see any loving care for a long time, I went ahead and fixed
> this performance degradation myself, based on patches by Stefan Kangas
> and their discussions in this bug report.

Thanks, I appreciate the help.

[I had intended to get to it this weekend based on your recent ping; for
 me this stuff (as opposed to ELisp shenanigans) requires a decent chunk
 of time to sit down and properly focus.]

> The feature whereby we check whether shadowing of consecutive keys is
> by the same command, which AFAIU is what caused the regression, is now
> optional, by default off.  There's a new variable,
> 'describe-bindings-check-shadowing-in-ranges', which can be used to
> turn it on, and an optional value of that variable,
> 'ignore-self-insert', which provides some partial testing of shadowing
> in these cases by trading accuracy for performance.

OK.  The bug doesn't directly affect me, but now people who are affected
can enable the bug fix.

> And I have a question about this whole "shadowing detection" feature.
> If I repeat the recipe of bug#9293, which started all this, i.e.
>
>   emacs -Q
>   C-x C-f some-tarball-file.tar.gz RET
>   M-x view-mode RET
>   C-h m
>
> then the *Help* buffer shows this at its start:
>
>   key             binding
>   ---             -------
>
>   0 .. 9	digit-argument
>   e		tar-extract  (currently shadowed by ‘View-exit’)
>   f		tar-extract
>
>   C-d		tar-flag-deleted
>   RET		tar-extract
>     (this binding is currently shadowed)
>   C-n		tar-next-line
>   C-p		tar-previous-line
>   SPC		tar-next-line
>     (this binding is currently shadowed)
>   C		tar-copy
>     (this binding is currently shadowed)
>
> Note how the shadowing of 'e' is described with the command that
> shadows it, but the shadowing of RET, SPC, and 'C' isn't.  Why is
> that?  Is that a separate bug?

It is a separate bug, I think.  The "currently shadowed part" is new in
commit fb9326b45c76, but it was never fixed for the second case.

Which of the two messages is shown has to do with whether or not this is
a regular keymap or a sparse keymap.  They were always handled slightly
differently, but now we have the changed message for one of them that
makes this visible.

> for some reason bug#9293 discussed only a small part of the *Help*
> display and never looked beyond that.

I overlooked the case you mention, indeed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 18 Sep 2021 13:26:02 GMT) Full text and rfc822 format available.

Message #81 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: stephen.berman <at> gmx.net, juri <at> linkov.net, handa <at> gnu.org, styang <at> fastmail.com,
 monnier <at> iro.umontreal.ca, larsi <at> gnus.org, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sat, 18 Sep 2021 16:24:41 +0300
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Sat, 18 Sep 2021 05:34:08 -0700
> Cc: stephen.berman <at> gmx.net, handa <at> gnu.org, juri <at> linkov.net, 
> 	styang <at> fastmail.com, monnier <at> iro.umontreal.ca, 45379 <at> debbugs.gnu.org, 
> 	Lars Ingebrigtsen <larsi <at> gnus.org>
> 
> >   key             binding
> >   ---             -------
> >
> >   0 .. 9	digit-argument
> >   e		tar-extract  (currently shadowed by ‘View-exit’)
> >   f		tar-extract
> >
> >   C-d		tar-flag-deleted
> >   RET		tar-extract
> >     (this binding is currently shadowed)
> >   C-n		tar-next-line
> >   C-p		tar-previous-line
> >   SPC		tar-next-line
> >     (this binding is currently shadowed)
> >   C		tar-copy
> >     (this binding is currently shadowed)
> >
> > Note how the shadowing of 'e' is described with the command that
> > shadows it, but the shadowing of RET, SPC, and 'C' isn't.  Why is
> > that?  Is that a separate bug?
> 
> It is a separate bug, I think.  The "currently shadowed part" is new in
> commit fb9326b45c76, but it was never fixed for the second case.

Then I guess we can close this bug?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45379; Package emacs. (Sat, 18 Sep 2021 14:40:02 GMT) Full text and rfc822 format available.

Message #84 received at 45379 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: stephen.berman <at> gmx.net, juri <at> linkov.net, handa <at> gnu.org, styang <at> fastmail.com,
 monnier <at> iro.umontreal.ca, larsi <at> gnus.org, 45379 <at> debbugs.gnu.org
Subject: Re: bug#45379: 28.0.50;
 Degraded Performance of describe-buffer-bindings
Date: Sat, 18 Sep 2021 07:39:07 -0700
tags 45379 + fixed
close 45379 28.1
thanks

Eli Zaretskii <eliz <at> gnu.org> writes:

> Then I guess we can close this bug?

I think so, yes, so I'm doing that now.

If anyone is still seeing any issues related to this feel free to either
reply back or just open a new bug.




Added tag(s) fixed. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sat, 18 Sep 2021 14:40:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 45379 <at> debbugs.gnu.org and styang <at> fastmail.com Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sat, 18 Sep 2021 14:40:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 17 Oct 2021 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 189 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.