Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting Room List Causes Mode Reinitialization #146

Closed
treed opened this issue May 10, 2023 · 12 comments
Closed

Reverting Room List Causes Mode Reinitialization #146

treed opened this issue May 10, 2023 · 12 comments
Assignees
Milestone

Comments

@treed
Copy link
Contributor

treed commented May 10, 2023

While investigating an issue with UI pauses while Ement is running, I found that the proximate cause is the sync callback reverting the room list. This revert runs ement-room-list-mode again, which calls a bunch of other mode initialization things.

From what I can tell, the root cause of the slowness is add-hook sorting based on a depth list which has a lot of entries, which is its own problem, but alphapapa says that the revert shouldn't be reinitializing the mode anyway and that I should file an issue.

Here's a bit of the profile I captured, demonstrating the codepath:

        5185  50%         - plz--sentinel
        4900  47%          - #<compiled -0x1b4cf30a72447de8>
        4900  47%           - #<compiled 0x155d2ecf629f4be3>
        4900  47%            - apply
        4900  47%             - ement--sync-callback
        4900  47%              - run-hook-with-args
        4898  47%               - ement-room-list-auto-update
        4898  47%                - revert-buffer
        4898  47%                 - ement-room-list-revert
        4898  47%                  - ement-room-list
        4894  47%                   - ement-room-list-mode
        4894  47%                    - magit-section-mode
        4838  46%                     - special-mode
         747   7%                      - global-font-lock-mode-cmhh
         746   7%                       - add-hook
         746   7%                        - #<compiled -0x6171969eebf39b2>
         169   1%                           alist-get
         742   7%                      + envrc-global-mode-cmhh
         724   7%                      + global-jinx-mode-cmhh
         715   6%                      + whole-line-or-region-global-mode-cmhh
         685   6%                      + yas-global-mode-cmhh
         672   6%                      + global-eldoc-mode-cmhh
         553   5%                      + magit-auto-revert-mode-cmhh
          54   0%                     + add-hook
           3   0%                   + taxy-magit-section-insert
           1   0%                   + taxy-magit-section-format-items
           1   0%               - ement--auto-sync
           1   0%                - ement--sync
           1   0%                 + ement-api

This is with ement 0.8.1 via ELPA.

@alphapapa
Copy link
Owner

Thanks.

First, please note that v0.8.3 is the version currently on ELPA. So if you could, please test that version first.

If the problem still happens, please try this branch: https://github.com/alphapapa/ement.el/compare/wip/146

@alphapapa alphapapa added this to the 0.9 milestone May 14, 2023
@alphapapa alphapapa self-assigned this May 14, 2023
@alphapapa alphapapa modified the milestones: 0.9, 0.10 May 14, 2023
@treed
Copy link
Contributor Author

treed commented May 15, 2023

Okay, I'm on 0.9.1 now and I'll see abotu reproducing it.

@treed
Copy link
Contributor Author

treed commented May 18, 2023

I can confirm the callpath still exists as of 0.9.2:

        3860  34%       - ement-room-list-auto-update
        3860  34%        - revert-buffer
        3860  34%         - ement-room-list-revert
        3850  34%          - ement-room-list
        3540  31%           - ement-room-list-mode
        3331  29%            - magit-section-mode
        3165  28%             - special-mode

@alphapapa
Copy link
Owner

Did you try the branch I pushed?

@treed
Copy link
Contributor Author

treed commented May 19, 2023

Which branch? From the other issue?

@alphapapa
Copy link
Owner

The one I linked in this comment: #146 (comment)

@treed
Copy link
Contributor Author

treed commented May 19, 2023

Woow, I'm super blind. My bad. I'll check it out tomorrow.

@treed
Copy link
Contributor Author

treed commented May 24, 2023

Yeah, that seems to do the trick.

@alphapapa
Copy link
Owner

Ok, I'll push this change to master and let it mellow for a while. Thanks.

@alphapapa
Copy link
Owner

alphapapa commented May 28, 2023

So, IIUC, what's happening is that, in some users' configs, they have many global minor modes activated (or certain ones which are slow to initialize), and when the room list is updated and the major mode is reinitialized, these global modes are reinitialized, which the user perceives as Emacs blocking.

Alternatively (or together with that), there's an issue in Emacs's add-hook function that can cause poor performance depending on how many global mode hooks are activated and whether they have a specified depth. (@treed: If this is so, please file an Emacs bug report so it can be looked into.)

I'm guessing that this is particular to user configuration, because I've never experienced this problem in my usage; the room list buffer updates so quickly that no blocking is perceptible.

Nevertheless, as was said, it shouldn't be necessary for the room list's major mode to be reinitialized when the buffer is updated, so the change now on master should solve the problem.

User feedback on this change would be appreciated (e.g. @sielicki) so it can be confirmed to work well before tagging the next release. Thanks.

@sielicki
Copy link

Apologies for being unable to test this for you prior to the release, but I have noticed that this is improved after picking up 0.10

@alphapapa
Copy link
Owner

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants