Subject: bug#61436: Emacs Freezing With Java Files

From: Eli Zaretskii <[email-masked]>
Date: Sun, 12 Feb 2023 08:00:04 +0200

> Date: Sat, 11 Feb 2023 18:16:41 +0000
> From:  Hank Greenburg via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> I have a few Java files that are about 500 lines of code and I can't move around in them much before Emacs
> freezes. I first thought it was java-lsp but it still happened after disabling and uninstalling it. I also uninstalled
> lsp-mode as well, but that didn't change anything. 
> 
> I started doing CPU profiles of it and found that which-function-mode was taking up 67% of my CPU usage.
> While this is happening all I was doing was holding the down arrow until it froze about 350 lines in. Didn't
> press any other buttons. 
> 
> So I disabled which-function-mode and moved around the buffer just fine! Though when trying to edit the file
> (just hit enter), it froze again. This time it seems like electric-indent-mode was taking up close to 50% of my
> CPU usage. 
> 
> I disabled that and tried again and then it froze again with c-indent-line-or-region eating up 63% of my CPU
> when I use TAB.
> 
> While using debug-on-quit I get the below output. Any idea what's happening here and how it can be
> addressed? I do know though that if I launch emacs with the -Q argument, then there aren't any problems at
> all. I tried large files of other types and it only seems to happen with Java files. I attached screenshots of the
> CPU profiler outputs for each of the three scenarios. Attached is also the Java file as well as my init file. 
> 
> I am using emacs version 28.2 on EndeavorOS, but reproduced the results using both emacs 29 and the
> master branch. 

I confirm that the issue doesn't happen with "emacs -Q" and the file
you posted.  So some of your customizations trigger the problem, and
we must find out which one(s).  Can you try selectively enabling only
parts of your init files to find which customizations are the reason?
If your customizations are not too many, starting "emacs -Q" and then
evaluating the customizations one by one could be a good way of
finding the culprit(s).  Another possibility is bisecting:
successively divide the init file in two halves and see which half
causes the problem, then divide that half in tow, etc. etc., until you
get to a small enough part you can post here (or figure out yourself).

Thanks.