Previous: Gforth in pipes, Up: Gforth Environment
If Gforth is used for CGI scripts or in shell scripts, its startup
speed may become a problem. On a 300MHz 21064a under Linux-2.2.13 with
glibc-2.0.7, gforth -e bye
takes about 24.6ms user and 11.3ms
system time.
If startup speed is a problem, you may consider the following ways to improve it; or you may consider ways to reduce the number of startups (for example, by using Fast-CGI).
An easy step that influences Gforth startup speed is the use of the --no-dynamic option; this decreases image loading speed, but increases compile-time and run-time.
Another step to improve startup speed is to statically link Gforth, by
building it with XLDFLAGS=-static
. This requires more memory for
the code and will therefore slow down the first invocation, but
subsequent invocations avoid the dynamic linking overhead. Another
disadvantage is that Gforth won't profit from library upgrades. As a
result, gforth-static -e bye
takes about 17.1ms user and
8.2ms system time.
The next step to improve startup speed is to use a non-relocatable image
(see Non-Relocatable Image Files). You can create this image with
gforth -e "savesystem gforthnr.fi bye"
and later use it with
gforth -i gforthnr.fi ...
. This avoids the relocation overhead
and a part of the copy-on-write overhead. The disadvantage is that the
non-relocatable image does not work if the OS gives Gforth a different
address for the dictionary, for whatever reason; so you better provide a
fallback on a relocatable image. gforth-static -i gforthnr.fi -e
bye
takes about 15.3ms user and 7.5ms system time.
The final step is to disable dictionary hashing in Gforth. Gforth
builds the hash table on startup, which takes much of the startup
overhead. You can do this by commenting out the include hash.fs
in startup.fs and everything that requires hash.fs (at the
moment table.fs and ekey.fs) and then doing make
.
The disadvantages are that functionality like table
and
ekey
is missing and that text interpretation (e.g., compiling)
now takes much longer. So, you should only use this method if there is
no significant text interpretation to perform (the script should be
compiled into the image, amongst other things). gforth-static -i
gforthnrnh.fi -e bye
takes about 2.1ms user and 6.1ms system time.