Subject: Re: bug#71367: 30.0.50; ELPA package breadcrumb causes Emacs freeze when editing json file

From: Eli Zaretskii <[email-masked]>
Date: Thu, 06 Jun 2024 12:35:38 +0300

> Cc: [email-masked], Theodor Thornhill <[email-masked]>,
>  João Távora <[email-masked]>
> From: Andrea Corallo <[email-masked]>
> Date: Wed, 05 Jun 2024 05:36:23 -0400
> 
> Tassilo Horn <[email-masked]> writes:
> 
> > Ok, now I tested with
> >
> >   emacs -Q --load ~/[email-masked]
> >
> > where the recipe is:
> >
> > (progn
> >   ;; Native compile doesn't make a difference...
> >   (setq native-comp-jit-compilation-deny-list '(".*breadcrumb.*"))
> >   (package-initialize)
> >   (package-activate 'breadcrumb)
> >   (breadcrumb-mode)
> >   ;; Using json-ts-mode is essential!
> >   (add-to-list 'major-mode-remap-alist '(js-json-mode . json-ts-mode))
> >   (find-file "~/mirrorstatus.json"))
> >
> > Before firing up Emacs, I've deleted the breadcrumb ELN file.
> >
> > With the above recipe, Emacs instantly freezes when the file gets
> > displayed.

It doesn't freeze, it just takes a very long time to perform the
initial redisplay after visiting the file.  With my unoptimized build
of Emacs 30, it takes something like a full minute until the "freeze"
ends.  Optimized builds should do that in, like, 15 to 20 sec, I'd
expect.  Thereafter the breadcrumbs display on the header line works
just fine.

The importance of using json-ts-mode is simply because it defines
support for Imenu, whereas the default js-json-mode does not.  With
Imenu support turned on, imenu--index-alist is a huge nested structure
for this large file: there are 17500 elements there.  The first time
breadcrumb-mode is invoked, it loops over all those elements doing its
thing in breadcrumb--summarize, and that takes both time and a lot of
consing (which triggers a lot of GC, which slows down this even more).
That's all.

Maybe João could suggest some trick or user option to cut down that
initial time to reasonable level.  Failing that, I suggest not to
enable breadcrumb-mode in such large JSON buffers (something that can
be done in a mode hook, I guess?)