Faster Launching MacVim Windows – Don’t Fork
Friday, August 29th, 2008I read an interesting message on the MacVim mailing list this morning about the speed of opening new windows with the mvim command - a shell command that's included in the MacVim package. What the developer (the main maintainer) did was to time several ways of opening up the window and the sub-components of that process. What he found was that the fork() was about two-thirds of the time! Surely, there is a faster way to do this.
And there is... he even had an answer: don't fork on opening a new window from the command line. The change to the mvim script is pretty easy. Change the script from:
if [ "$gui" ]; then # Note: this isn't perfect, because any error output goes to the # terminal instead of the console log. # But if you use open instead, you will need to fully qualify the # path names for any filenames you specify, which is hard. exec "$binary" -g $opts ${1:+"$@"} else exec "$binary" $opts ${1:+"$@"} fi
to:
if [ "$gui" ]; then # Note: this isn't perfect, because any error output goes to the # terminal instead of the console log. # But if you use open instead, you will need to fully qualify the # path names for any filenames you specify, which is hard. exec "$binary" -g -f $opts ${1:+"$@"} <&0 & else exec "$binary" $opts ${1:+"$@"} fi
This takes the launch time from a little over a second on my MacBook Pro to less than half a sec. OK, sure... is this that important? No, of course not, but the change is not bad, either. Not forking is a good way to keep system load down. Doesn't hurt, and that it's faster is even better.
So... if you're using MacVim - think about updating the mvim script and try it. It's a good idea.