Subject: bug#53606: 29.0.50; Very slow Customize buffer for bibtex-biblatex-entry-alist

From: Mauro Aranda <[email-masked]>
Date: Sat, 9 Sep 2023 19:23:16 -0300

Lars Ingebrigtsen <[email-masked]> writes:

 > `M-x customize-option RET bibtex-biblatex-entry-alist RET'
 >
 > takes a very long time -- more than 20 seconds on this laptop.  It's a
 > long alist, but it shouldn't take that long.

I don't have any concrete ideas on how to speed it up on the Widget
library side.  But looking at the defcustom for
bibtex-biblatex-entry-alist I noted two things that can help to create
the Customize buffer more quickly:

1) It uses a custom widget derived from the lazy widget, but doesn't
provide a :tag.  That makes it look awful and giving it a proper :tag 
reduced
the buffer creation time somewhat in my testings.

2) More importantly, the bibtex-entry-alist widget looks like this:
(define-widget 'bibtex-entry-alist 'lazy
   "Format of `bibtex-BibTeX-entry-alist' and friends."
   :type '(repeat (group (string :tag "Entry type")
                         (string :tag "Documentation")
                         (repeat :tag "Required fields"
                                 (group (string :tag "Field")
                                        (option (choice :tag "Comment" 
:value nil
                                                        (const nil) string))
                                        (option (choice :tag "Init" 
:value nil
                                                        (const nil) 
string function))
                                        (option (choice :tag 
"Alternative" :value nil
                                                        (const nil) 
integer))))
                         (repeat :tag "Crossref fields"
                                 (group (string :tag "Field")
                                        (option (choice :tag "Comment" 
:value nil
                                                        (const nil) string))
                                        (option (choice :tag "Init" 
:value nil
                                                        (const nil) 
string function))
                                        (option (choice :tag 
"Alternative" :value nil
                                                        (const nil) 
integer))))
                         (repeat :tag "Optional fields"
                                 (group (string :tag "Field")
                                        (option (choice :tag "Comment" 
:value nil
                                                        (const nil) string))
                                        (option (choice :tag "Init" 
:value nil
                                                        (const nil) 
string function))
                                        (option (choice :tag 
"Alternative" :value nil
                                                        (const nil) 
integer)))))))

Why combine option and choice? That's redundant, specially since the
choice widget allows for the nil value.  Removing the `option's and just
leaving the `choice's should be equivalent in functionality, and in my
testings reduced the creation time to the half.

I ran customize-option 5 times and got:

With `option':
(172.526219636 69 6.120602505999997)

Without `option':
(86.260726994 42 3.5430049540000113)

This is without native compilation.

Based on the above results and since there's no lost in functionality, I
propose to make the changes to the bibtex-entry-alist widget. It is a
net gain in speed, and it might make the wait bearable.