ananthakumaran / monky

Magit for Hg
http://ananthakumaran.in/monky/index.html
GNU General Public License v3.0
154 stars 30 forks source link

Basic use of Mercurial's command server #9

Closed ghost closed 12 years ago

ghost commented 12 years ago

Hi,

first, thank you for your great monky package.

When using monky I realized that for some operations it takes a lot of time. The reason seems to be that monky executes several mercurial commands during a single operation and the startup time of mercurial/python slows down the whole process considerably. For those purposes, when some external program needs to run several commands, the hg guys implemented the command server since version 1.9.

I implemented a basic approach using the command server. The idea is to execute hg commands within the scope of an monky-with-process block which spawn a single process in command-server mode and executes all commands within this context. I provide special versions for those commands that actually run the process namely monky-cmdserver-process-file and monky-cmdserver-run*.

In order to enable the command server on must customize the variable monky-process-type and set it to 'cmdserver (the default nil means to run the original versions of all commands without command server).

Currently only the synchronous commands are executed within the command server, all asynchronous commands still use the standard way.

On my machine the command server approach makes monky be much more responsive than before. On a repo with 13 unchanged files a simple update of the status buffer requires more than 4 seconds without the command server and less than one second with the command server.

It may even be possible to keep the command server running all the time which may improve the performance further, but then one may get problems when the repository is changed from outside emacs. I think the current approach is a good compromise.

Please let me know what you think of these changes.

Best regards, Frank

ananthakumaran commented 12 years ago

Hi,

Thanks for the patch.

I feel monky-process shouldn't be used to hold both the cmdserver process and ordinary process. Have a look at https://github.com/ananthakumaran/monky/commit/8e75d6dbd83287e508cb5144e576c42334054a74. I am using seperate var for the two process.

ghost commented 12 years ago

Having a separate variable is probably a very good idea ;)

tkf commented 12 years ago

The issue of command server ("after starting the server, changes made to the repository (commit, push, pull etc) not through the server may not show when querying the server") is fixed in Mercurial 2.0.

So, monky can keep running command server, if it stops supporting command server of Mercurial <2.0. It would be nice to have faster monky.

ananthakumaran commented 12 years ago
ghost commented 12 years ago

When I wrote the command-server patch I experimented with a single command server, too. Besides being more difficult to implement (one has to keep one command-server open per repository, not per buffer, deal with dangling open command servers from closed buffers, ...) the impression was that the speed gain was negligible (usually hg starts in less than a second, which is okay). Using the command-server per refresh was the compromise because a single refresh may run a lot of hg commands and refresh, which is probably the most common operation. Until there are really performance problems that could be solved by using a single command server, I would vote to keep with the current approach.

tkf commented 12 years ago

@lyro Thank you very much. Now I understand the implementation difficulty.

@ananthakumaran Yes, I agree with you that supporting 1.9 while most people having it is good idea. I don't know much about implementation around processing, but my guess is that keeping the command server process increases speed when you are browsing log. There is some delay when you hit p/n until you see the diffs in the current version.