Subject: bug#48871: 27.2; Unusably slow in C# mode

From: jan <[email-masked]>
Date: Sun, 6 Jun 2021 19:00:57 +0100

Looks like strings doing it.

Go to fundamental mode (or search&replace will take forever),
completely remove all strings with regex replace:

".*?" ->

Save file then close and reopen emacs, reopen file, ensure it's in
csharp mode, char insertion is almost back to normal.

That is, remove strings entirely. Just replacing them with empty
strings "" didn't help.

cheers

jan

On 06/06/2021, Eli Zaretskii <[email-masked]> wrote:
>> From: jan <[email-masked]>
>> Date: Sun, 6 Jun 2021 15:53:11 +0100
>> Cc: [email-masked]
>>
>> I don't recall installing c# but may well have happened.
>> >From package-list-packages:
>>
>> csharp-mode        20210328.2004 installed             C# mode derived
>> mode
>>
>> Which does not say built-in so likely I did. Looking in the unzipped
>> emacs 27.2 , no relevant *sharp* file in it, and did find it in the
>> elpa directory, so I guess must have.
>>
>> Started with -Q.  Did the M-x load-file for csharp-mode.el (FYI also
>> had to do load-file for csharp-compilation.el before that to make it
>> happy).
>>
>> Finally got to load the C# file itself, exactly the same. No faster.
>>
>> Troublesome C# file attached.
>
> Thanks.
>
> Alan, can you look into this?  It could be some problem in
> csharp-mode, but the profiler says 97% of the time is spent in a CC
> mode code, so maybe you can shed some light on this?
>
> I see that almost the entire 6896-line file is enclosed in a single
> "namespace LDB { ... }" block, maybe this is the reason?
>
> Here's the main portion of a profile measured on my system from just
> inserting 3 characters at BOB of the file attached by the OP.  An
> unoptimized build of Emacs 28 took about 2 min(!) to process those 3
> self-inserting characters.
>
> 	  8693  98% - command-execute
> 	  8693  98%  - call-interactively
> 	  8693  98%   - funcall-interactively
> 	  8690  98%    - self-insert-command
> 	  8627  98%     - c-before-change
> 	  8627  98%      - mapc
> 	  8627  98%       - #<compiled 0x1aaa1ff2c62de223>
> 	  8627  98%        - c-before-change-check-unbalanced-strings
> 	  8611  97%           c-pps-to-string-delim
> 	    10   0%         - c-syntactic-re-search-forward
> 	     2   0%          - c-beginning-of-macro
> 	     2   0%             back-to-indentation
> 	     1   0%            #<compiled 0x4f47ef635173>
> 	     1   0%           c-clear-syn-tab
> 	    63   0%     - c-after-change
>