emacsorphanage / git-gutter

Emacs port of GitGutter which is Sublime Text Plugin
841 stars 71 forks source link

Optimization #26

Closed syohex closed 10 years ago

syohex commented 11 years ago

Emacs is slow when git-gutter-mode is enable. because a function git-gutter is called a lot of times at window-configuration-change-hook.

I should optimization it.

ahyatt commented 11 years ago

With this project in mind, I've improved emacs-memoize (https://github.com/skeeto/emacs-memoize), so that you can memoize by buffer contents. You should consider using this so that git diff is called only once per buffer version. You may have to confine such functionality to emacs 24 and above, since I believe the memoization library only works for emacs 24 due to use of lexical bindings.

syohex commented 11 years ago

Thanks nice information. I'll check it.

m2ym commented 10 years ago

Could you please tell me why window-configuration-change-hook is needed? I think it should be used very carefully, otherwise turned off by default for good performance.

m2ym commented 10 years ago

I'm trying to improve git-gutter performance and have faced some issues/questions.

  1. Obtaining git root directory is really needed?

    git diff --relative may solve a path finding problem.

  2. Why synchronous process execution is used?

    Asynchronous processing seems to be easy for this case.

  3. Why you keep state variables such like git-gutter:base-file-name?

    They make the program hard to understand, IMHO. Furthermore, they make the program somewhat buggy. For example, git-gutter:base-file-name seems to keep the old value even if the buffer file name has been changed.

  4. Iterating over window-list is really needed?

    It looks to me that it's enough to update the current buffer.

I think that (2) might be a sweet spot of git-gutter performance.

Thanks.

syohex commented 10 years ago

@m2ym

Could you please tell me why window-configuration-change-hook is needed? I think it should be used very carefully, otherwise turned off by default for good performance.

Because I want to update git diff information after magit commands or git commands (add, reset etc) with in eshell. We can update git diff information after M-x magit-status or M-x eshell with window-configuration-change-hook, because window configuration is changed after such commands.

But it makes too slowly as you say. We should not use it as possible. But I don't know how to archive my purpose without window-configuration-change-hook.

ahyatt commented 10 years ago

Maybe you could advise a few well-chosen defuns?

On Tuesday, February 25, 2014 10:38:43 AM, Syohei YOSHIDA < notifications@github.com> wrote:

@m2ym https://github.com/m2ym

Could you please tell me why window-configuration-change-hook is needed? I think it should be used very carefully, otherwise turned off by default for good performance.

Because I want to update git diff information after magit commands or gitcommands (add, reset etc) with in eshell. We can update git diff information after M-x magit-status or M-x eshell with window-configuration-change-hook, because window configuration is changed after such commands.

But it makes too slowly as you say. We should not use it as possible. But I don't know how to archive my purpose without window-configuration-change-hook.

Reply to this email directly or view it on GitHubhttps://github.com/syohex/emacs-git-gutter/issues/26#issuecomment-36020314 .

syohex commented 10 years ago

@m2ym

(2) Why synchronous process execution is used? Asynchronous processing seems to be easy for this case.

I implemented asynchronous version but it has little effect for speed. I think there are too many updating by window-configuration-change-hook. If we does not use window-configuration-change-hook, asynchrnous processing makes sence for speed.

(4) Iterating over window-list is really needed? It looks to me that it's enough to update the current buffer.

I introduced it for indirect buffer. Can we update indirect buffer without checking all buffer in window ?

m2ym commented 10 years ago

@syohex

Because I want to update git diff information after magit commands or git commands (add, reset etc) with in eshell. We can update git diff information after M-x magit-status or M-x eshell with window-configuration-change-hook, because window configuration is changed after such commands.

I think in that case after-revert-hook works well. Am I right?

I implemented asynchronous version but it has little effect for speed. I think there are too many updating by window-configuration-change-hook. If we does not use window-configuration-change-hook, asynchrnous processing makes sence for speed.

Cool. Can I use that version?

I introduced it for indirect buffer. Can we update indirect buffer without checking all buffer in window ?

I don't understand yet why we need to care about indirect buffers? What is the use case?

Thanks.

syohex commented 10 years ago

Because I want to update git diff information after magit commands or git commands (add, reset etc) with in eshell. We can update git diff information after M-x magit-status or M-x eshell with window-configuration-change-hook, because window configuration is changed after such commands.

I think in that case after-revert-hook works well. Am I right?

I think after-revert-hook works only when source code is changed such as git checkout, git reset --hard. Source code is not changed after git add, git reset but git status is changed. I tested whether after-revert-hook is called after git add, it is not called. However we can use it by overriding buffer-stale-function which is used for whether file is reverted(changed).

I implemented asynchronous version but it has little effect for speed. I think there are too many updating by window-configuration-change-hook. If we does not use window-configuration-change-hook, asynchrnous processing makes sence for speed. Cool. Can I use that version?

Sorry I can't find. It been a while I implemented. I'll try to search it.

I introduced it for indirect buffer. Can we update indirect buffer without checking all buffer in window ? I don't understand yet why we need to care about indirect buffers? What is the use case?

Someone want to edit HTML and Javascript or CSS with indirect buffer at once. In such case, one buffer is updated, the other buffer should be update because those buffers refer to same file. But many users does not use indirect buffer, so it might be optional.

m2ym commented 10 years ago

I think after-revert-hook works only when source code is changed such as git checkout, git reset --hard. Source code is not changed after git add, git reset but git status is changed. I tested whether after-revert-hook is called after git add, it is not called. However we can use it by overriding buffer-stale-function which is used for whether file is reverted(changed).

after-save-hook helps you in such cases. I don't think users really want to update buffers immediately after executing git commands out of Emacs, at the cost of performance.

Sorry I can't find. It been a while I implemented. I'll try to search it.

Maybe I can implement it.

Someone want to edit HTML and Javascript or CSS with indirect buffer at once. In such case, one buffer is updated, the other buffer should be update because those buffers refer to same file. But many users does not use indirect buffer, so it might be optional.

I have never used indirect buffers. I think it should be optional if it costs speed and most of users don't use it.

syohex commented 10 years ago

I think after-revert-hook works only when source code is changed such as git checkout, git reset --hard. Source code is not changed after git add, git reset but git status is changed. I tested whether after-revert-hook is called after git add, it is not called. However we can use it by overriding buffer-stale-function which is used for whether file is reverted(changed).

after-save-hook helps you in such cases. I don't think users really want to update buffers immediately after executing git commands out of Emacs, at the cost of performance.

I see. Users can control update timing by hooks(magit hooks, focus-in-hook etc) or timer function. Update point should be small as possible for performance.

Sorry I can't find. It been a while I implemented. I'll try to search it.

Maybe I can implement it.

Thanks

Someone want to edit HTML and Javascript or CSS with indirect buffer at once. In such case, one buffer is updated, the other buffer should be update because those buffers refer to same file. But many users does not use indirect buffer, so it might be optional.

I have never used indirect buffers. I think it should be optional if it costs speed and most of users don't use it.

OK, it will be optional at future version.

syohex commented 10 years ago

Sorry git-gutter does not update indirect buffers until users use make-indirect-buffer. So update function are never called for users who do not use indirect buffer.

m2ym commented 10 years ago

Good.

syohex commented 10 years ago

46 I start implementation.

m2ym commented 10 years ago

:+1: