rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re:  Speed of rc
@ 1993-04-08 22:31 Tom Culliton x2278
  1993-04-09  0:38 ` Scott Schwartz
  0 siblings, 1 reply; 19+ messages in thread
From: Tom Culliton x2278 @ 1993-04-08 22:31 UTC (permalink / raw)
  To: haahr; +Cc: rc

me> When running commands or scripts it seems that rc often takes longer
me> than it should, especially compared to sh or ksh.

paul> i don't find this true at all.  i haven't ever used ksh seriously, but
paul> rc feels (that's not is, but feels) much faster than sh on all machines
paul> i've tried it on.

I've actually rewritten rc scripts for sh so that they would be used by
more of our users, and seen notable speed differences.  (I'm talking
about jobs that take minutes (in either shell) rather than seconds
here, can run up to a couple hundred lines of script and chew up whole
directory hierarchies and many megabytes of data.)  Except in cases
where rc made it easy to use a better algorithm, which created fewer
processes or invoked fewer external commands, sh wins.

There seem to be a couple of components to this.  First sh has test
builtin, and on our machines, for rc to use test means firing up sh to
do it.  Second when I use pattern matching to any significant extent,
or do lots of fiddling with lists, rc seems to bog down.  Heavy `{}
usage also seems to chew lots of time.

Don't get me wrong, this is not meant to be a criticism of rc, I love
it and wouldn't want to give it up.  It was about 10 times easier to
write the scripts in rc than it would be in sh, and they're often much
smaller and cleaner.  Using rc encourages me to write things when it
wouldn't seem worth the effort in sh or (shudder!) perl.  (I think that
Perl is exactly the wrong solution for the same reasons that PL/1 was.)

paul> the last major performance
paul> tweak that i recall was that there were some list operations being done
paul> in O(n^2) time when they didn't have to be, and that fixed, but i'm not
paul> sure if that was a pre- or post-1.4 change.

I remember this as a pre-1.4 change, but operations on big lists still
seem to take a fair amount of time.

paul> profiling code & looking for hot spots is always a good thing to do.
paul> i think you'll find that rc is pretty much flat and not spending an
paul> inordinate amount of time in any particular kind of operation.

The difference may well be simply one of usage styles, and the answer
may be as simple as some hints about how to improve the efficiency of
rc scripts.  For example using find where appropriate is usually a BIG
win especially since test isn't builtin. 

Tom

PS - I actually spent a fair amount of time once trying to figure out a
stunt to run co-processes under rc so I can fire up sh (for test), and
something else to do math, exactly once and then have functions that
talk to them.  In the end I decided it either couldn't be done or
wasn't worth the effort.


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: speed of rc
@ 1993-04-15 20:26 Tom Culliton x2278
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Culliton x2278 @ 1993-04-15 20:26 UTC (permalink / raw)
  To: byron, john; +Cc: rc

Since I started this thread I wanted stop for a moment to agree whole
heartedly with John in praise of rc.  My experience is that Byron's rc
is completely stable, bug free, solid as a rock, easily ported, clean,
polished, a pleasure to use, etc.  My comments definitely fall into the
category of nitpicking. I've pushed it in all sorts of strange and
intresting ways, and (aside from a porting bug caused by SCO's flakey
signal.h) never had it fail.  Byron has nothing to apologize for and a
great deal to be very proud of.

To Byron in particular: The design philosophy behind rc has my
strongest endorsement, perl is a monster, and like one of those "all in
one" kitchen gadgets I find it completely useless.  It is unstable and
buggy, takes forever to port, and otherwise generally makes my head
ache.  My concerns about the speed of rc come from trying to do big
production type jobs with it and trying to evangelize to the unwashed
sh/csh types around here.  (Our sysadmins can't even be bothered to
support bash, and do ksh only grudgingly.  Since rc is simple enough
for anyone to understand and bug free, it would be a perfect solution,
if I could only overcome peoples inertia.)

Byron's point about analyzing rc with prof is well taken, there are a
couple of gotchas to beware of though.  People often make to much of
flattening out the usage peaks.  A high peak doesn't necessarily mean
that means that a certain section of code is a bottle neck, it could
mean the code is optimal and efficiently doing it's work in a tight
loop. (e.g. A document format to format translator that spends 95% of
it's time in 5 lines of code that handle normal text.)  Nor does a flat
profile means that the code is optimal, it could very well mean that
lots of code extra code is getting executed. (e.g. In the translator
mentioned above doing character by character i/o rather than buffered.)
And when a program is system call bound, as Byron indicates is the case
with rc, there is still the possibility of extraneous calls. (such as
the stat call that Dave Mason and Byron mention)

Dave Mason also makes an excellent point about the size of the
environment under rc and the effect on the cost of execs.  Writing in
rc it is often natural to stick things into lists in the enviroment,
which would be in a file or pipe under sh.  Especially when trying to
avoid external programs for the sake of speed.  The fact that all
variables and functions are exported adds to this.  It wouldn't suprise
me if this was were part of my time was going under SCO ODT.  A good
thing to remember when writing scripts.

Remember, I'm not throwing stones here, just asking a question: What
can we do (if anything, and short of polluting rc with extra builtins)
to speed rc up?

Tom

PS - sorry this was so long...


^ permalink raw reply	[flat|nested] 19+ messages in thread
* speed of rc
@ 1993-04-13 20:26 Byron Rakitzis
  1993-04-13 21:23 ` John Mackin
  0 siblings, 1 reply; 19+ messages in thread
From: Byron Rakitzis @ 1993-04-13 20:26 UTC (permalink / raw)
  To: rc

John pointed out to me that the rc path search does a stat() before
an exec(), even for an absolute path name. Optimizing out that
stat should take care of the "pus" problem, if indeed that file
is full of lines which say "/tmp/xx".

Disclaimer: I haven't tried to reproduce any of this stuff here yet.
Further disclaimer: I want to offer my apologies for not spending
more time on rc, but things have really never been busier for me
as a programmer.


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re:  Speed of rc
@ 1993-04-12  5:51 Paul Haahr
  0 siblings, 0 replies; 19+ messages in thread
From: Paul Haahr @ 1993-04-12  5:51 UTC (permalink / raw)
  To: dmason, rc

i haven't read most of this note, (still catching up on my mail), but

> any idea why the es executable is so large?

it shrinks in size dramatically if you turn off assertions.  some of the
things that have to be done for the garbage collector generate a lot of
assertions which should really just be compile-time checks.

the other thing is that es has lots of functionality (taken generally
out of the shared libraries, with only a little bit of glue code) that
rc does not have, even if it is minor:  ~-expansion, builtin time(), etc.
a lot of this can be thought of as code bloat.  nevertheless, es w/o
assertions should be roughly the size of a csh linked in the same way.

thanks for your analysis.

paul


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re:  Speed of rc
@ 1993-04-09 15:58 Tom Culliton x2278
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Culliton x2278 @ 1993-04-09 15:58 UTC (permalink / raw)
  To: haahr; +Cc: rc

Paul writes:
> ok, now i understand what's going on.  yes, if you use test a lot in rc,
> it will go slowly.  if your /bin/sh has a test builtin, that will run faster.
> there's no surprises here, you're just comparing apples and oranges.

The issue can't be dismissed that easily.  I've seen relatively pokey
behaviour even in scripts that have been written using exclusively
builtin functions.  I'm not espousing the idea of building test into
rc, just asking if some tuning could be done, particularly in the areas
that I mentioned before.

Tom


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re:  Speed of rc
@ 1993-04-08 23:09 Paul Haahr
  0 siblings, 0 replies; 19+ messages in thread
From: Paul Haahr @ 1993-04-08 23:09 UTC (permalink / raw)
  To: culliton; +Cc: rc

ok, now i understand what's going on.  yes, if you use test a lot in rc,
it will go slowly.  if your /bin/sh has a test builtin, that will run faster.
there's no surprises here, you're just comparing apples and oranges.

i think that there are two very good reasons that test is not built into rc:
(1) with one glaring exception (echo), rc really has no extraneous builtins,
and (2) the semantics of test are, at best, awful.  in addition, i know that
Byron hesitated before deviating seriously from the bell labs version of rc.

personally, if test had nice semantics, i would prefer to see it built in
to rc.  it doesn't.

paul

ps:  as many of you know, Byron and i have been doing a new shell, es, in
which we felt no obligation to be compatible with rc.  es needed to have
a builtin for doing some test-like things because path-searching is done
by functions written in es rather than c.  because of this, we exposed an
access function, which does many things that test does, albeit cleaner.


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re:  Speed of rc
@ 1993-04-08 20:14 Byron Rakitzis
  0 siblings, 0 replies; 19+ messages in thread
From: Byron Rakitzis @ 1993-04-08 20:14 UTC (permalink / raw)
  To: culliton, haahr; +Cc: rc

I seem to remember the "benchmark" posted on c.u.s as being quite
artificial.

That said, I'll tell you what I know about rc's speed: I don't think
you will make rc ever go faster by examining prof output. The fat
just isn't there. The slowest routine is probably yacc, but it's not
even close to the time you spend in Unix system calls.

The problem can be viewed in one of two ways: either (1) rc is
not perl, or (2) Unix is too slow. Take your pick. rc has to go
do fork/exec for a lot of tasks which a featureful shell or
perl might cram in as a builtin.

I agree that the speed at which scripts run is a valid concern,
and all I can say is that I don't have a good answer at this
time. I can't bring myself to buy into the perl philosophy.


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re:  Speed of rc
@ 1993-04-08 15:45 Paul Haahr
  0 siblings, 0 replies; 19+ messages in thread
From: Paul Haahr @ 1993-04-08 15:45 UTC (permalink / raw)
  To: culliton; +Cc: rc

> When running commands or scripts it seems that rc often takes longer
> than it should, especially compared to sh or ksh.

i don't find this true at all.  i haven't ever used ksh seriously, but
rc feels (that's not is, but feels) much faster than sh on all machines
i've tried it on.

> I also seem to
> remember seeing something in comp.unix.shell within the last couple of
> months, about the relative speed of various shells, which showed rc as
> being substantially slower.

i don't remember it that way.  as i recall, the numbers from rc looked
about the same as all other shells, which was not surprising, given that
the benchmark seemed to be testing just how fast the machine forked.

> What this leads me to wonder is, if anyone
> has ever bothered to do any serious timing tests or profile rc and find
> out where it's spending its time?

i know that Byron had done this on at least several times during his work
on rc, but i don't think he's done it recently.  the last major performance
tweak that i recall was that there were some list operations being done
in O(n^2) time when they didn't have to be, and that fixed, but i'm not
sure if that was a pre- or post-1.4 change.

profiling code & looking for hot spots is always a good thing to do.
i think you'll find that rc is pretty much flat and not spending an
inordinate amount of time in any particular kind of operation.

paul


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Speed of rc
@ 1993-04-07 19:50 Tom Culliton x2278
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Culliton x2278 @ 1993-04-07 19:50 UTC (permalink / raw)
  To: rc

When running commands or scripts it seems that rc often takes longer
than it should, especially compared to sh or ksh.  I also seem to
remember seeing something in comp.unix.shell within the last couple of
months, about the relative speed of various shells, which showed rc as
being substantially slower.  What this leads me to wonder is, if anyone
has ever bothered to do any serious timing tests or profile rc and find
out where it's spending its time?

I raised this issue with Byron once, but he had bigger fish to fry at
the time. (and rightly so)  However the shell has been stable for quite
a while, and it might be well worth exploring, especially now that a
version 1.5 is being considered.

Tom


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~1993-04-15 21:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-04-08 22:31 Speed of rc Tom Culliton x2278
1993-04-09  0:38 ` Scott Schwartz
1993-04-09 15:23   ` John Mackin
1993-04-13 19:26     ` Chris Siebenmann
1993-04-13 21:13       ` John Mackin
1993-04-09 16:32   ` Dave Mason
1993-04-09 16:39     ` John Mackin
1993-04-09 19:22       ` Dave Mason
1993-04-09 21:12         ` Chris Siebenmann
  -- strict thread matches above, loose matches on Subject: below --
1993-04-15 20:26 speed " Tom Culliton x2278
1993-04-13 20:26 Byron Rakitzis
1993-04-13 21:23 ` John Mackin
1993-04-13 23:42   ` mycroft
1993-04-12  5:51 Speed " Paul Haahr
1993-04-09 15:58 Tom Culliton x2278
1993-04-08 23:09 Paul Haahr
1993-04-08 20:14 Byron Rakitzis
1993-04-08 15:45 Paul Haahr
1993-04-07 19:50 Tom Culliton x2278

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).