4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Many people struggle to find out why Vim startup is slow.
12 Solution: Add the --startuptime command line flag.
13 Files: runtime/doc/starting.txt, src/globals.h, src/feature.h,
14 src/main.c, src/macros.h
17 *** ../vim-7.2.268/runtime/doc/starting.txt 2008-11-09 13:43:25.000000000 +0100
18 --- runtime/doc/starting.txt 2009-10-25 11:57:51.000000000 +0100
25 + --startuptime={fname} *--startuptime*
26 + During startup write timing messages to the file {fname}.
27 + This can be used to find out where time is spent while loading
28 + your .vimrc and plugins.
29 + When {fname} already exists new messages are appended.
30 + {only when compiled with this feature}
33 --literal Take file names literally, don't expand wildcards. Not needed
34 for Unix, because Vim always takes file names literally (the
38 window title and copy/paste using the X clipboard. This
39 avoids a long startup time when running Vim in a terminal
40 emulator and the connection to the X server is slow.
41 + See |--startuptime| to find out if affects you.
42 Only makes a difference on Unix or VMS, when compiled with the
43 |+X11| feature. Otherwise it's ignored.
44 To disable the connection only for specific terminals, see the
45 *** ../vim-7.2.268/src/globals.h 2009-07-29 12:09:49.000000000 +0200
46 --- src/globals.h 2009-10-10 15:14:31.000000000 +0200
50 /* For undo we need to know the lowest time possible. */
51 EXTERN time_t starttime;
54 + EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */
58 * Some compilers warn for not using a return value, but in some situations we
59 * can't do anything useful with the value. Assign to this variable to avoid
60 *** ../vim-7.2.268/src/feature.h 2008-11-09 13:43:25.000000000 +0100
61 --- src/feature.h 2009-10-10 16:16:19.000000000 +0200
67 ! * STARTUPTIME Time the startup process. Writes a "vimstartup" file
70 ! /* #define STARTUPTIME "vimstartup" */
73 * MEM_PROFILE Debugging of memory allocation and freeing.
78 ! * STARTUPTIME Time the startup process. Writes a file with
81 ! #if defined(FEAT_NORMAL) \
82 ! && ((defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)) \
83 ! || defined(WIN3264))
84 ! # define STARTUPTIME 1
88 * MEM_PROFILE Debugging of memory allocation and freeing.
89 *** ../vim-7.2.268/src/main.c 2009-05-26 22:58:43.000000000 +0200
90 --- src/main.c 2009-10-10 16:18:32.000000000 +0200
97 - static FILE *time_fd = NULL;
101 * Different types of error messages.
107 char_u *fname = NULL; /* file name from command line */
108 mparm_T params; /* various parameters passed between
109 * main() and other functions. */
115 * Do any system-specific initialisations. These can NOT use IObuff or
121 ! time_fd = mch_fopen(STARTUPTIME, "a");
122 ! TIME_MSG("--- VIM STARTING ---");
124 starttime = time(NULL);
130 ! for (i = 1; i < argc; ++i)
132 ! if (STRNICMP(argv[i], "--startuptime=", 14) == 0)
134 ! time_fd = mch_fopen(argv[i] + 14, "a");
135 ! TIME_MSG("--- VIM STARTING ---");
140 starttime = time(NULL);
150 + /* Now that we have drawn the first screen all the startup stuff
151 + * has been done, close any file for startup messages. */
152 + if (time_fd != NULL)
154 + TIME_MSG("first screen update");
155 + TIME_MSG("--- VIM STARTED ---");
162 if (need_mouse_correct)
166 /* already processed, skip */
169 + else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0)
171 + /* already processed, skip */
175 if (argv[0][argv_idx])
180 static struct timeval prev_timeval;
184 + * Windows doesn't have gettimeofday(), although it does have struct timeval.
187 + gettimeofday(struct timeval *tv, char *dummy)
190 + tv->tv_sec = t / CLOCKS_PER_SEC;
191 + tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
197 * Save the previous time before doing something that could nest.
198 * set "*tv_rel" to the time elapsed so far.
206 - * Windows doesn't have gettimeofday(), although it does have struct timeval.
209 - gettimeofday(struct timeval *tv, char *dummy)
212 - tv->tv_sec = t / CLOCKS_PER_SEC;
213 - tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
220 #if defined(FEAT_CLIENTSERVER) || defined(PROTO)
222 *** ../vim-7.2.268/src/macros.h 2009-05-17 13:30:58.000000000 +0200
223 --- src/macros.h 2009-10-10 15:19:07.000000000 +0200
229 ! # define TIME_MSG(s) time_msg(s, NULL)
237 ! # define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
241 *** ../vim-7.2.268/src/version.c 2009-11-03 11:43:05.000000000 +0100
242 --- src/version.c 2009-11-03 12:06:31.000000000 +0100
246 { /* Add new patch number below this line */
252 BEDEVERE: Look! It's the old man from scene 24 - what's he Doing here?
253 ARTHUR: He is the keeper of the Bridge. He asks each traveler five
255 GALAHAD: Three questions.
256 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
258 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
259 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
260 \\\ download, build and distribute -- http://www.A-A-P.org ///
261 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///