rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: Tim Goodwin <tjg@star.le.ac.uk>
To: rc@hawkwind.utcs.toronto.edu
Subject: Dynamically loading readline on demand (was Re: rc futures)
Date: Wed, 5 Jan 2000 06:59:36 -0500	[thread overview]
Message-ID: <ezkAAOYxczhcXQwA@ltsun0.star.le.ac.uk> (raw)
In-Reply-To: <199912151632.LAA19961@smtp3.fas.harvard.edu>

> > 23. Dynamically load readline only when rc is about to read from a
> > terminal device.

> What operating system doesn't demand-load the binaries anyway?
> If you're not using the readline code, (the large majority of) it won't
> be resident in memory.

Sure, but it still slows down fork().  My guess is that this is because
of the extra page table entries to be managed.  I swear I'm not making
this up, and I have data to prove it.  But first, let's examine the
status quo.

Specifying `--with-readline' to the rc configure script ends up simply
appending `-lreadline' to the link command line (and maybe `-ltermcap'
or similar).  This will link rc against readline either dynamically, if
the linker finds a libreadline.so, or statically, if the linker only
finds libreadline.a or you said `-static' or similar.

The INSTALL documentation has this advice to offer.

                              It is a good idea to specify static linking
    (unless you are linking against a dynamic readline library)---if you are
    using gcc, you can do this by setting `CFLAGS=-static'.

My assumption when I wrote this was that readline is big enough that
it's always worth linking against it dynamically if you can.  That was a
clear violation of the rule: "profile, don't speculate!", so now let me
make amends...

I took an rc script that does nothing (makes no system calls) except
fork() and wait() 10000 times.  Dividing the total CPU time to run the
script by 10000 gives an average loop time.

There are two variables of interest: static versus dynamic linking,
and no-readline versus readline; giving four variants of rc to try.
(Remember that rc always needs the C library.)

Here are the results I got on my 200MHz Linux PC (us = microseconds).

    rc.static      744us
    rc.rl.static   865us
    rc.dynamic    1071us
    rc.rl.dynamic 1442us

(The raw data, together with file sizes, are appended.  Lest you think
that this is a quirk of Linux, I have even more dramatic results from
SunOS 5.  Why does dynamic linking increase the user time?  I have no
idea, but it reliably does on both these platforms.)

My conclusion from this is that using readline is an insignificant
(although measurable) performance hit.  But dynamic linking is always a
bad idea.

I therefore intend to drop my suggestion that rc should itself load
readline on demand, and instead to make the following minor changes
for rc-1.6b3.

1. Modify the INSTALL documentation; we should always recommend linking
statically.

2. Modify configure.in, so that, if we are using gcc, `-static' is
specified.

Any comments?

Tim.


   text	   data	    bss	    dec	    hex	filename
 347773	  13204	  16008	 376985	  5c099	rc.static
12.58user 61.78system 1:14.52elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (100040major+2150702minor)pagefaults 0swaps

   text	   data	    bss	    dec	    hex	filename
 427989	  25748	  19500	 473237	  73895	rc.rl.static
13.07user 73.42system 1:26.66elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (200044major+2281366minor)pagefaults 0swaps

   text	   data	    bss	    dec	    hex	filename
  65580	   8492	  11360	  85432	  14db8	rc.dynamic
21.16user 85.95system 1:47.22elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (200100major+2449872minor)pagefaults 0swaps

   text	   data	    bss	    dec	    hex	filename
  67213	   8532	  11552	  87297	  15501	rc.rl.dynamic
30.07user 114.15system 2:24.65elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (200117major+2827443minor)pagefaults 0swaps


  reply	other threads:[~2000-01-05 23:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-15 16:32 rc futures Russ Cox
2000-01-05 11:59 ` Tim Goodwin [this message]
2000-01-01  0:22   ` Dynamically loading readline on demand (was Re: rc futures) Paul Haahr
2000-01-14 16:26     ` Tim Goodwin
2000-01-14 19:18       ` Paul Haahr
2000-01-13  0:19   ` Jeremy Fitzhardinge
2000-01-07 10:38 Bengt Kleberg
2000-01-14 11:11 Bengt Kleberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ezkAAOYxczhcXQwA@ltsun0.star.le.ac.uk \
    --to=tjg@star.le.ac.uk \
    --cc=rc@hawkwind.utcs.toronto.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).