Subject: Re: bug#59641: term is very slow

From: Akib Azmain Turja <[email-masked]>
Date: Sat, 17 Dec 2022 00:29:02 +0600

Eli Zaretskii <[email-masked]> writes:

>> Date: Mon, 28 Nov 2022 02:00:29 +0600
>> From:  Akib Azmain Turja via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> Term mode is very slow.  On my computer, Coterm is 2-3x faster than
>> term, and my own terminal emulator, Eat, is 4-5x faster.
>> 
>> I tried to profile Term.  Steps:
>> 
>> 1. emacs -Q (+ -nw, environment variable DISPLAY was unset)
>> 2. M-x profiler-start RET cpu+mem RET
>> 3. M-x term
>> 4. Run the following stupid command:
>>    timeout 1 bash -c 'i=0 ; while true ; do echo $i ; i=$((i+1)) ; done'
>>    Note I also run emacs -nw in before this command.
>> 5. Wait for finishing.
>> 6. M-x profiler-stop
>> 7. M-x profiler-report
>> 
>> Here are the reports (attached), but don't seem to be human readable:
>
> Copy them from the display shown by profiler-report, after you expand it
> completely.
>
> And the "cpu" profile is enough; the "mem" one doesn't add anything useful.

Sorry, I missed this reply.  I found this in debbugs.gnu.org.  :O

Here is the data:  (I didn't redo the steps, I just did
'M-x profiler-find-profile RET path/to/profile'.  ;)  )

--8<---------------cut here---------------start------------->8---
        9397  95% - term-emulate-terminal
        2710  27%  - term-handle-ansi-escape
        1831  18%   - term-down
           8   0%      term-move-columns
         765   7%   - term-goto
         714   7%      term-down
          82   0%   - term--handle-colors-list
          66   0%    - term--color-as-hex
          34   0%     - face-background
          34   0%      - face-attribute
          20   0%       - face-attribute-merged-with
          16   0%          face-attribute
           6   0%         face-attribute
          32   0%     - face-foreground
          20   0%      - face-attribute
           8   0%         face-attribute
        1846  18%  - term-down
          68   0%   - vertical-motion
          68   0%    - jit-lock-function
          68   0%     - jit-lock-fontify-now
          28   0%      - jit-lock--run-functions
           8   0%       - #<compiled -0x1552f4e0aae95e03>
           8   0%        - font-lock-fontify-region
           8   0%         - font-lock-default-fontify-region
           8   0%            font-lock-unfontify-region
           8   0%       - #<compiled -0x1554fa224e318f03>
           8   0%        - font-lock-fontify-region
           8   0%           font-lock-default-fontify-region
           4   0%       - #<compiled -0x1546c88d0dca1d03>
           4   0%        - font-lock-fontify-region
           4   0%         - font-lock-default-fontify-region
           4   0%            font-lock-extend-region-wholelines
           4   0%       - #<compiled -0x1546c2ed8adb7d03>
           4   0%          font-lock-fontify-region
          68   0%   - term-insert-char
          28   0%      jit-lock-after-change
          28   0%     term-move-columns
         379   3%  - vertical-motion
         363   3%   - jit-lock-function
         317   3%    - jit-lock-fontify-now
         155   1%     - run-with-timer
         155   1%      - run-at-time
         100   1%       - timer-activate
          96   0%        - timer--activate
           8   0%           timer--time-less-p
          20   0%         timer-set-time
          98   0%     - jit-lock--run-functions
          22   0%      - #<compiled -0x1552ff392e9c9603>
          22   0%         font-lock-fontify-region
          20   0%      - #<compiled -0x1552f71a36b2fc03>
          20   0%       - font-lock-fontify-region
          20   0%        - font-lock-default-fontify-region
          20   0%         - font-lock-extend-region-wholelines
          20   0%            syntax-propertize-wholelines
          20   0%      - #<compiled -0x1546fd5b53d9da03>
          20   0%       - font-lock-fontify-region
          20   0%          font-lock-default-fontify-region
          12   0%      - #<compiled -0x1552f745b3231203>
          12   0%       - font-lock-fontify-region
          12   0%        - font-lock-default-fontify-region
          12   0%           font-lock-extend-region-wholelines
          12   0%      - #<compiled -0x1540fac747b55603>
          12   0%       - font-lock-fontify-region
          12   0%        - font-lock-default-fontify-region
          12   0%           font-lock-unfontify-region
           8   0%        #<compiled -0x1540fac747b55603>
           4   0%      - #<compiled -0x1540f619efa85203>
           4   0%       - font-lock-fontify-region
           4   0%          font-lock-set-defaults
         235   2%  - term-move-columns
          10   0%     term-move-to-column
         137   1%    term-handle-deferred-scroll
         111   1%    jit-lock-after-change
          24   0%  - redisplay_internal (C function)
           8   0%   - term--update-term-menu
           8   0%    - easy-menu-change
           8   0%     - easy-menu-add-item
           8   0%      - easy-menu-get-map
           8   0%       - mapcar
           8   0%        - #<compiled 0x12afad0b062c4ebb>
           8   0%           easy-menu-lookup-name
           8   0%   - jit-lock-function
           8   0%    - jit-lock-fontify-now
           8   0%     - jit-lock--run-functions
           4   0%      - #<compiled -0x1540fe59cc42d603>
           4   0%       - font-lock-fontify-region
           4   0%          font-lock-set-defaults
           4   0%      - #<compiled -0x1540fe59cc42d603>
           4   0%         font-lock-fontify-region
           8   0%   - eval
           4   0%      if
          12   0%    syntax-ppss-flush-cache
          12   0%  - timer-event-handler
          12   0%   - apply
           4   0%    - show-paren-function
           4   0%     - show-paren--default
           4   0%        syntax-ppss
           8   0%  - eval
           8   0%     if
           4   0%  - jit-lock-function
           4   0%   - jit-lock-fontify-now
           4   0%    - jit-lock--run-functions
           4   0%       #<compiled -0x1546deb559806303>
         347   3% - ...
         347   3%    Automatic GC
         127   1% - command-execute
          82   0%  - funcall-interactively
          77   0%   - execute-extended-command
          65   0%    - command-execute
          53   0%     - byte-code
          26   0%      - require
          26   0%         byte-code
           4   0%      - read-shell-command
           4   0%         read-from-minibuffer
           8   0%       funcall-interactively
           4   0%     - defvar
           4   0%        byte-code
           4   0%     term-send-raw
          45   0%  - byte-code
          45   0%   - read-extended-command
          45   0%    - read-extended-command-1
          40   0%     - completing-read-default
          11   0%      - timer-event-handler
          11   0%       - apply
           7   0%          #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_9>
           4   0%        - show-paren-function
           2   0%           show-paren--default
           3   0%        #<compiled -0xa873503662230e4>
           6   0% - timer-event-handler
           6   0%  - apply
           4   0%   - #<compiled -0xb30f43a056c4866>
           4   0%    - execute-extended-command--shorter
           4   0%       #<compiled 0x1a044bbfab7de9f2>
           2   0%   - show-paren-function
           2   0%      buffer-match-p
           2   0% - redisplay_internal (C function)
           2   0%  - redisplay--pre-redisplay-functions
           2   0%   - run-hook-with-args
           2   0%      redisplay--update-region-highlight
--8<---------------cut here---------------end--------------->8---

-- 
Akib Azmain Turja, GPG key: 70018CE5819F17A3BBA666AFE74F0EFA922AE7F5
Fediverse: [email-masked]
Codeberg: akib
emailselfdefense.fsf.org | "Nothing can be secure without encryption."