Subject: bug#57245: 29.0.50; M-> in a large XML file (without long lines) is slow

From: Eli Zaretskii <[email-masked]>
Date: Tue, 16 Aug 2022 19:54:54 +0300

> Date: Tue, 16 Aug 2022 17:33:58 +0300
> From: Dmitry Gutov <[email-masked]>
> 
> Prerequisite: Have an XML file that is 20 MB in size, and doesn't have
> long lines.
> 
> Or follow steps 1-3 to create one.
> 
> 1. wget -o large-file.xml 
> https://updates.drupal.org/release-history/drupal/current
> 2. M-% /> RET ^J/> RET (to break up the long line into smaller pieces)
> 3. Select the contents of the file and copy them over and over for 99
> times. Alternatively, copy them 9 times, then select the result, and
> copy it 9 times as well. Save the buffer.
> 
> (To try to keep XML valid -- not sure if necessary -- you can only
> perform the copying operation on the contents of the <releases> tag. But
> that's probably not important. I did that, though.)
> 
> 4. Kill the buffer and re-visit it again. Press M->.
> 5. Note the delay.
> 
> Here's the profiler output:
> 
>          1397  95% - command-execute
>          1397  95%  - call-interactively
>          1338  91%   - funcall-interactively
>          1331  90%    - end-of-buffer
>          1327  90%     - recenter
>          1327  90%      - jit-lock-function
>          1327  90%       - jit-lock-fontify-now
>          1327  90%        - jit-lock--run-functions
>          1327  90%         - run-hook-wrapped
>          1327  90%          - #<compiled -0x14ecf3ff276f01c3>
>          1327  90%           - font-lock-fontify-region
>          1327  90%            - font-lock-default-fontify-region
>          1327  90%             - nxml-extend-region
>           845  57%              - skip-syntax-forward
>           845  57%               - internal--syntax-propertize
>           845  57%                - syntax-propertize
>           845  57%                 - nxml-syntax-propertize
>           845  57%                  - sgml-syntax-propertize
>           842  57%                   - #<compiled 0x1894bdc3ad4ca90>
>           479  32%                      sgml--syntax-propertize-ppss
>             3   0%                     syntax-ppss
>           482  32%              - nxml-move-outside-backwards
>           482  32%               - nxml-inside-start
>           482  32%                  syntax-ppss
>             7   0%    + execute-extended-command
>            59   4%   + byte-code
>            59   4% + ...
>            10   0% + timer-event-handler
> 

Thanks.  It looks like some problem in nXML mode or in syntax.c or in
how nXML uses the syntax stuff.  Maybe the code there is simply not
scalable.

Stefan, can you see why syntax-related stuff in sgml-mode is so heavy
here?  What the above profile doesn't show is that this code creates
tons of garbage, so GC is called a lot, and adds its share of
slowdown.